Modification in turn functionality

Removed the turn functionality that uses the timeline, now in the turning tiles you are free to do a movement to left or right and the animation is faster than the previous version
This commit is contained in:
JKuijperM 2023-03-12 12:51:43 +01:00
parent 183adf599b
commit 64d66c4982
7 changed files with 41 additions and 134 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:96b498c17899f18649d1af2a84fb121464381a57d2c720e1b67754a4c459cd5a
size 35291
oid sha256:51c2a5da66d7a584e0b591a3262e7c49d15cd71dfe53e23254247a3e78962698
size 35097

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5808943abab611606f9d0a28be192c9e5053fd47d01dc7468b6b313c098d71ca
size 36884
oid sha256:368e355640209d925f14b1aa209150fae69e0fdc8cc6ea88769dceed6c6766ef
size 36928

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:53b5e0b7bc251e49906f5431f804f40c17b8757bd776e8c2643c2a8e2ca29b2d
size 37056
oid sha256:302d46c4efd912d483f97d9e2e469566dd5eca88883381779e45b2924ec3e0f0
size 37105

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:da11530fbc1a44bde5eed884dd45e343c6a6bc6e85e5d8ef8dd4f2989067ed62
oid sha256:1e1083088494b22be0ef59e2488e878366780e1ad135ab336512208a4fd3a114
size 5608

View File

@ -27,23 +27,6 @@ void ATileCurve::TurnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
if (ZombieCharacter != nullptr)
{
if (!bWasTriggered)
{
if (bTurnRight && !bTurnLeft)
{
ZombieCharacter->bStraight = false;
ZombieCharacter->iSideTurn = 1;
}
else if (!bTurnRight && bTurnLeft)
{
ZombieCharacter->bStraight = false;
ZombieCharacter->iSideTurn = -1;
}
else
{
UE_LOG(LogTemp, Error, TEXT("[ATileCurve::OnBeginOverlapChild] You should not be here, check if bTurnRight and bTurnLeft have the same value."))
}
bWasTriggered = true;
}
ZombieCharacter->bCanTurn = true;
}
}

View File

@ -52,15 +52,6 @@ AZombieCharacter::AZombieCharacter()
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
FollowCamera->SetWorldRotation(FQuat(FRotator(-15.f, 0.f, 0.f)));
// For timeline
bReadyState = true;
mDirections.Add(0, FVector(1, 0, 0));
mDirections.Add(1, FVector(0, 1, 0));
mDirections.Add(2, FVector(-1, 0, 0));
mDirections.Add(3, FVector(0, -1, 0));
vCurrentDirection = mDirections[0];
}
// Called when the game starts or when spawned
@ -75,19 +66,6 @@ void AZombieCharacter::BeginPlay()
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
}
//CurrentRotation = GetActorRotation();
if (TurnCurve)
{
FOnTimelineFloat TimelineCallback;
FOnTimelineEventStatic TimelineFisihedCallback;
TimelineCallback.BindUFunction(this, FName("ControlTurning"));
TimelineFisihedCallback.BindUFunction(this, FName("SetState"));
TurnTimeline.AddInterpFloat(TurnCurve, TimelineCallback);
TurnTimeline.SetTimelineFinishedFunc(TimelineFisihedCallback);
}
}
// Called every frame
@ -96,15 +74,9 @@ void AZombieCharacter::Tick(float DeltaTime)
Super::Tick(DeltaTime);
if (!bDied)
{
TurnTimeline.TickTimeline(DeltaTime);
if (!bTurning)
{
MoveForwardConstant(DeltaTime);
}
}
}
// Called to bind functionality to input
@ -120,6 +92,8 @@ void AZombieCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
// Moving
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AZombieCharacter::Move);
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Started, this, &AZombieCharacter::CanTurn);
// Crouching
//EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Triggered, this, &AZombieCharacter::Crouch);
@ -141,17 +115,22 @@ void AZombieCharacter::Move(const FInputActionValue& Value)
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get forward vector
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
// get right vector
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// add movement
AddMovementInput(ForwardDirection, MovementVector.Y);
AddMovementInput(RightDirection, MovementVector.X);
}
}
void AZombieCharacter::CanTurn(const FInputActionValue& Value)
{
float fTurnSide = Value.Get<FVector2D>().X;
if (bCanTurn)
{
rDesireRotation = rDesireRotation + FRotator(0.f, fTurnSide * 90.f, 0.f);
bCanTurn = false;
}
}
void AZombieCharacter::RestartLevel()
{
@ -191,64 +170,29 @@ void AZombieCharacter::Die()
void AZombieCharacter::MoveForwardConstant(float DeltaTime)
{
if (bStraight)
if (Controller)
{
TurnCorner(DeltaTime);
// find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get forward vector
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
//UE_LOG(LogTemp, Warning, TEXT("%f"), fBaseSpeed);
FVector vLocation = GetActorLocation();
fBaseSpeed += fAcceleration * DeltaTime;
vLocation += GetActorForwardVector() * fBaseSpeed;
SetActorLocation(vLocation);
//AddMovementInput(ForwardDirection, .5f, true);
}
else
{
RotateCharacter();
bStraight = true;
}
}
void AZombieCharacter::PlayTurn()
void AZombieCharacter::TurnCorner(float DeltaTime)
{
bTurning = true;
if (fControlTurn < 90.f)
if (GetControlRotation() != rDesireRotation)
{
TurnTimeline.PlayFromStart();
}
else
{
fControlTurn = 0.f;
FRotator rNewRotation = FMath::RInterpTo(GetControlRotation(), rDesireRotation, DeltaTime, fTurnSpeed);
Controller->SetControlRotation(rNewRotation);
}
}
void AZombieCharacter::RotateCharacter()
{
FRotator CurrentRotation = GetActorRotation();
fControlTurn = 0.f;
PlayTurn();
}
void AZombieCharacter::ControlTurning()
{
fTimelineValue = TurnTimeline.GetPlaybackPosition();
float fTurnCurve = TurnCurve->GetFloatValue(fTimelineValue);
float fVal = fTurnCurve - fPrevCurvValue;
fPrevCurvValue = fTurnCurve;
fControlTurn += fVal;
if (fControlTurn <= 90.f)
{
FRotator CurrentRotation = Controller->GetControlRotation();
CurrentRotation.Yaw += fVal * iSideTurn;
Controller->SetControlRotation(CurrentRotation);
}
}
void AZombieCharacter::SetState()
{
bReadyState = true;
bTurning = false;
bStraight = true;
fPrevCurvValue = 0.f;
}

View File

@ -52,6 +52,7 @@ protected:
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
void Move(const FInputActionValue& Value);
void CanTurn(const FInputActionValue& Value);
//void Crouch(const FInputActionValue& Value);
void RestartLevel();
@ -70,28 +71,10 @@ public:
UPROPERTY(EditAnywhere, Category = "Movement")
float fAcceleration = .001f;
void RotateCharacter();
bool bStraight = true;
int iSideTurn = 1;
// Properties for the timeline to turn right
UFUNCTION()
void ControlTurning();
UFUNCTION()
void SetState();
bool bCanTurn = false;
FRotator rDesireRotation = FRotator(0.f, 0.f, 0.f);
UPROPERTY(EditAnywhere, Category = "Movement")
UCurveFloat* TurnCurve;
bool bReadyState;
float fCurveValue;
float fDistanceValue;
float fTimelineValue;
FTimeline TurnTimeline;
bool bTurning = false;
bool bRotate = false;
TMap<int, FVector> mDirections;
int iCurrentDirection = 0;
FVector vCurrentDirection;
float fTurnSpeed = 10.f;
void Die();
@ -99,11 +82,8 @@ private:
void MoveForwardConstant(float DeltaTime);
void PlayTurn();
float fControlTurn = 0.f;
float fPrevCurvValue = 0.f;
bool bDied = false;
void TurnCorner(float DeltaTime);
};