From 4fa44a809ac927172d56b5ef77f855baf77ddc90 Mon Sep 17 00:00:00 2001 From: JKuijperM Date: Sat, 7 Jan 2023 11:12:06 +0100 Subject: [PATCH] Added acceleration to the movement --- Content/Blueprints/BP_ZombieCharacter.uasset | 4 ++-- Source/EndlessZombie/ZombieCharacter.cpp | 11 +++-------- Source/EndlessZombie/ZombieCharacter.h | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Content/Blueprints/BP_ZombieCharacter.uasset b/Content/Blueprints/BP_ZombieCharacter.uasset index 62230a0..d46e062 100644 --- a/Content/Blueprints/BP_ZombieCharacter.uasset +++ b/Content/Blueprints/BP_ZombieCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a382241647580d65fcb11eaed49b5c9e28ca99e8efd50ddb5f8f7c27bce6d1ae -size 35058 +oid sha256:eae19cff0d1a7ec399f2bed7ddebeb12a0cd1464b7cc3aac8997e573ce9f340f +size 35109 diff --git a/Source/EndlessZombie/ZombieCharacter.cpp b/Source/EndlessZombie/ZombieCharacter.cpp index d4995f2..8793051 100644 --- a/Source/EndlessZombie/ZombieCharacter.cpp +++ b/Source/EndlessZombie/ZombieCharacter.cpp @@ -153,19 +153,14 @@ void AZombieCharacter::MoveForwardConstant(float DeltaTime) { if (bStraight) { - FVector vLocation = GetActorLocation(); - vLocation += GetActorForwardVector() * fBaseSpeed * DeltaTime; + FVector vLocation = GetActorLocation(); + fBaseSpeed += fAcceleration * DeltaTime; + vLocation += GetActorForwardVector() * fBaseSpeed; SetActorLocation(vLocation); } else { - RotateCharacter(); - FVector vLocation = GetActorLocation(); - /*FVector forward = GetActorForwardVector(); - UE_LOG(LogTemp, Warning, TEXT("x: %.2f, y: %.2f, z: %.2f"), forward.X, forward.Y, forward.Z);*/ - vLocation += vCurrentDirection * 30.f * DeltaTime; - SetActorLocation(vLocation); bStraight = true; } diff --git a/Source/EndlessZombie/ZombieCharacter.h b/Source/EndlessZombie/ZombieCharacter.h index 7c5f3db..f64267c 100644 --- a/Source/EndlessZombie/ZombieCharacter.h +++ b/Source/EndlessZombie/ZombieCharacter.h @@ -62,7 +62,9 @@ public: // Base speed UPROPERTY(EditAnywhere, Category = "Movement") - float fBaseSpeed = 100.f; + float fBaseSpeed = 5.f; + UPROPERTY(EditAnywhere, Category = "Movement") + float fAcceleration = .001f; void RotateCharacter(); bool bStraight = true;