Select randomly the tile to add to the path

This commit is contained in:
JKuijperM 2023-01-07 10:50:39 +01:00
parent 9526c2a754
commit 20063b408c
4 changed files with 8 additions and 11 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:4702776094ca194fc90b39435008fab198657e64f32856c9877692905f37138d oid sha256:f2428ad929b6fc4932acf4371f258f1fe703478b3cf4cf42f36332d751a4b2d7
size 36794 size 36794

View File

@ -6,7 +6,7 @@
// Sets default values // Sets default values
APathGenerator::APathGenerator() 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; PrimaryActorTick.bCanEverTick = true;
} }
@ -22,7 +22,7 @@ void APathGenerator::BeginPlay()
} }
AddSelectedTile(Tiles[1]); AddSelectedTile(Tiles[1]);
AddSelectedTile(Tiles[2]); AddSelectedTile(Tiles[2]);
} }
// Called every frame // Called every frame
@ -36,9 +36,11 @@ void APathGenerator::AddFloorTile()
{ {
if (Tiles[0] != nullptr) if (Tiles[0] != nullptr)
{ {
ATile* GeneratedTile = GetWorld()->SpawnActor<ATile>(Tiles[0], tNextSpawnPoint);
int iRandomIndex = FMath::RandRange(0, Tiles.Num() - 1);
ATile* GeneratedTile = GetWorld()->SpawnActor<ATile>(Tiles[iRandomIndex], tNextSpawnPoint);
tNextSpawnPoint = GeneratedTile->GetAttachTransform(); tNextSpawnPoint = GeneratedTile->GetAttachTransform();
} }
} }
void APathGenerator::AddSelectedTile(TSubclassOf<class ATile> Tile) void APathGenerator::AddSelectedTile(TSubclassOf<class ATile> Tile)

View File

@ -32,13 +32,11 @@ void ATileCurve::TurnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
{ {
if (bTurnRight && !bTurnLeft) if (bTurnRight && !bTurnLeft)
{ {
UE_LOG(LogTemp, Warning, TEXT("[ATileCurve::OnBeginOverlapChild] Rotating right"));
ZombieCharacter->bStraight = false; ZombieCharacter->bStraight = false;
ZombieCharacter->iSideTurn = 1; ZombieCharacter->iSideTurn = 1;
} }
else if (!bTurnRight && bTurnLeft) else if (!bTurnRight && bTurnLeft)
{ {
UE_LOG(LogTemp, Warning, TEXT("[ATileCurve::OnBeginOverlapChild] Rotating left"));
ZombieCharacter->bStraight = false; ZombieCharacter->bStraight = false;
ZombieCharacter->iSideTurn = -1; ZombieCharacter->iSideTurn = -1;
} }

View File

@ -195,7 +195,6 @@ void AZombieCharacter::ControlTurning()
{ {
fTimelineValue = TurnTimeline.GetPlaybackPosition(); fTimelineValue = TurnTimeline.GetPlaybackPosition();
float fTurnCurve = TurnCurve->GetFloatValue(fTimelineValue); float fTurnCurve = TurnCurve->GetFloatValue(fTimelineValue);
UE_LOG(LogTemp, Warning, TEXT("[AZombieCharacter::ControlTurning] TurnCurve: %f"), fTurnCurve);
float fVal = fTurnCurve - fPrevCurvValue; float fVal = fTurnCurve - fPrevCurvValue;
fPrevCurvValue = fTurnCurve; fPrevCurvValue = fTurnCurve;
@ -206,9 +205,7 @@ void AZombieCharacter::ControlTurning()
{ {
FRotator CurrentRotation = Controller->GetControlRotation(); FRotator CurrentRotation = Controller->GetControlRotation();
CurrentRotation.Yaw += fVal * iSideTurn; CurrentRotation.Yaw += fVal * iSideTurn;
Controller->SetControlRotation(CurrentRotation); 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);
} }
} }