From 20063b408caf75115b74958d7813b275ac7d0670 Mon Sep 17 00:00:00 2001 From: JKuijperM Date: Sat, 7 Jan 2023 10:50:39 +0100 Subject: [PATCH] Select randomly the tile to add to the path --- Content/Blueprints/Tiles/BP_TileTurnRight.uasset | 2 +- Source/EndlessZombie/PathGenerator.cpp | 10 ++++++---- Source/EndlessZombie/TileCurve.cpp | 2 -- Source/EndlessZombie/ZombieCharacter.cpp | 5 +---- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Content/Blueprints/Tiles/BP_TileTurnRight.uasset b/Content/Blueprints/Tiles/BP_TileTurnRight.uasset index ebc8972..e1bee07 100644 --- a/Content/Blueprints/Tiles/BP_TileTurnRight.uasset +++ b/Content/Blueprints/Tiles/BP_TileTurnRight.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4702776094ca194fc90b39435008fab198657e64f32856c9877692905f37138d +oid sha256:f2428ad929b6fc4932acf4371f258f1fe703478b3cf4cf42f36332d751a4b2d7 size 36794 diff --git a/Source/EndlessZombie/PathGenerator.cpp b/Source/EndlessZombie/PathGenerator.cpp index 1f53b78..d895e60 100644 --- a/Source/EndlessZombie/PathGenerator.cpp +++ b/Source/EndlessZombie/PathGenerator.cpp @@ -6,7 +6,7 @@ // Sets default values APathGenerator::APathGenerator() { - // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; } @@ -22,7 +22,7 @@ void APathGenerator::BeginPlay() } AddSelectedTile(Tiles[1]); AddSelectedTile(Tiles[2]); - + } // Called every frame @@ -36,9 +36,11 @@ void APathGenerator::AddFloorTile() { if (Tiles[0] != nullptr) { - ATile* GeneratedTile = GetWorld()->SpawnActor(Tiles[0], tNextSpawnPoint); + + int iRandomIndex = FMath::RandRange(0, Tiles.Num() - 1); + ATile* GeneratedTile = GetWorld()->SpawnActor(Tiles[iRandomIndex], tNextSpawnPoint); tNextSpawnPoint = GeneratedTile->GetAttachTransform(); - } + } } void APathGenerator::AddSelectedTile(TSubclassOf Tile) diff --git a/Source/EndlessZombie/TileCurve.cpp b/Source/EndlessZombie/TileCurve.cpp index dc96511..302884a 100644 --- a/Source/EndlessZombie/TileCurve.cpp +++ b/Source/EndlessZombie/TileCurve.cpp @@ -32,13 +32,11 @@ void ATileCurve::TurnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct { if (bTurnRight && !bTurnLeft) { - UE_LOG(LogTemp, Warning, TEXT("[ATileCurve::OnBeginOverlapChild] Rotating right")); ZombieCharacter->bStraight = false; ZombieCharacter->iSideTurn = 1; } else if (!bTurnRight && bTurnLeft) { - UE_LOG(LogTemp, Warning, TEXT("[ATileCurve::OnBeginOverlapChild] Rotating left")); ZombieCharacter->bStraight = false; ZombieCharacter->iSideTurn = -1; } diff --git a/Source/EndlessZombie/ZombieCharacter.cpp b/Source/EndlessZombie/ZombieCharacter.cpp index 5987094..d4995f2 100644 --- a/Source/EndlessZombie/ZombieCharacter.cpp +++ b/Source/EndlessZombie/ZombieCharacter.cpp @@ -195,7 +195,6 @@ void AZombieCharacter::ControlTurning() { fTimelineValue = TurnTimeline.GetPlaybackPosition(); float fTurnCurve = TurnCurve->GetFloatValue(fTimelineValue); - UE_LOG(LogTemp, Warning, TEXT("[AZombieCharacter::ControlTurning] TurnCurve: %f"), fTurnCurve); float fVal = fTurnCurve - fPrevCurvValue; fPrevCurvValue = fTurnCurve; @@ -206,9 +205,7 @@ void AZombieCharacter::ControlTurning() { FRotator CurrentRotation = Controller->GetControlRotation(); CurrentRotation.Yaw += fVal * iSideTurn; - Controller->SetControlRotation(CurrentRotation); - UE_LOG(LogTemp, Warning, TEXT("[AZombieCharacter::ControlTurning] Yaw: %f"), CurrentRotation.Yaw); - UE_LOG(LogTemp, Warning, TEXT("[AZombieCharacter::ControlTurning] Control Turn: %f"), fControlTurn); + Controller->SetControlRotation(CurrentRotation); } }