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:
parent
183adf599b
commit
64d66c4982
@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:96b498c17899f18649d1af2a84fb121464381a57d2c720e1b67754a4c459cd5a
|
oid sha256:51c2a5da66d7a584e0b591a3262e7c49d15cd71dfe53e23254247a3e78962698
|
||||||
size 35291
|
size 35097
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:5808943abab611606f9d0a28be192c9e5053fd47d01dc7468b6b313c098d71ca
|
oid sha256:368e355640209d925f14b1aa209150fae69e0fdc8cc6ea88769dceed6c6766ef
|
||||||
size 36884
|
size 36928
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:53b5e0b7bc251e49906f5431f804f40c17b8757bd776e8c2643c2a8e2ca29b2d
|
oid sha256:302d46c4efd912d483f97d9e2e469566dd5eca88883381779e45b2924ec3e0f0
|
||||||
size 37056
|
size 37105
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:da11530fbc1a44bde5eed884dd45e343c6a6bc6e85e5d8ef8dd4f2989067ed62
|
oid sha256:1e1083088494b22be0ef59e2488e878366780e1ad135ab336512208a4fd3a114
|
||||||
size 5608
|
size 5608
|
||||||
|
|||||||
@ -27,23 +27,6 @@ void ATileCurve::TurnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
|
|||||||
|
|
||||||
if (ZombieCharacter != nullptr)
|
if (ZombieCharacter != nullptr)
|
||||||
{
|
{
|
||||||
if (!bWasTriggered)
|
ZombieCharacter->bCanTurn = true;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,15 +52,6 @@ AZombieCharacter::AZombieCharacter()
|
|||||||
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
|
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
|
||||||
FollowCamera->SetWorldRotation(FQuat(FRotator(-15.f, 0.f, 0.f)));
|
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
|
// Called when the game starts or when spawned
|
||||||
@ -75,19 +66,6 @@ void AZombieCharacter::BeginPlay()
|
|||||||
Subsystem->AddMappingContext(DefaultMappingContext, 0);
|
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
|
// Called every frame
|
||||||
@ -96,16 +74,10 @@ void AZombieCharacter::Tick(float DeltaTime)
|
|||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
if (!bDied)
|
if (!bDied)
|
||||||
{
|
|
||||||
|
|
||||||
TurnTimeline.TickTimeline(DeltaTime);
|
|
||||||
|
|
||||||
if (!bTurning)
|
|
||||||
{
|
{
|
||||||
MoveForwardConstant(DeltaTime);
|
MoveForwardConstant(DeltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Called to bind functionality to input
|
// Called to bind functionality to input
|
||||||
void AZombieCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
void AZombieCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||||
@ -120,6 +92,8 @@ void AZombieCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
|
|||||||
|
|
||||||
// Moving
|
// Moving
|
||||||
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AZombieCharacter::Move);
|
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AZombieCharacter::Move);
|
||||||
|
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Started, this, &AZombieCharacter::CanTurn);
|
||||||
|
|
||||||
|
|
||||||
// Crouching
|
// Crouching
|
||||||
//EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Triggered, this, &AZombieCharacter::Crouch);
|
//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 Rotation = Controller->GetControlRotation();
|
||||||
const FRotator YawRotation(0, Rotation.Yaw, 0);
|
const FRotator YawRotation(0, Rotation.Yaw, 0);
|
||||||
|
|
||||||
// get forward vector
|
|
||||||
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
|
||||||
|
|
||||||
// get right vector
|
// get right vector
|
||||||
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
||||||
|
|
||||||
// add movement
|
// add movement
|
||||||
AddMovementInput(ForwardDirection, MovementVector.Y);
|
|
||||||
AddMovementInput(RightDirection, MovementVector.X);
|
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()
|
void AZombieCharacter::RestartLevel()
|
||||||
{
|
{
|
||||||
@ -191,64 +170,29 @@ void AZombieCharacter::Die()
|
|||||||
|
|
||||||
void AZombieCharacter::MoveForwardConstant(float DeltaTime)
|
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();
|
FVector vLocation = GetActorLocation();
|
||||||
fBaseSpeed += fAcceleration * DeltaTime;
|
fBaseSpeed += fAcceleration * DeltaTime;
|
||||||
vLocation += GetActorForwardVector() * fBaseSpeed;
|
vLocation += GetActorForwardVector() * fBaseSpeed;
|
||||||
SetActorLocation(vLocation);
|
SetActorLocation(vLocation);
|
||||||
|
//AddMovementInput(ForwardDirection, .5f, true);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
void AZombieCharacter::TurnCorner(float DeltaTime)
|
||||||
{
|
{
|
||||||
RotateCharacter();
|
if (GetControlRotation() != rDesireRotation)
|
||||||
bStraight = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void AZombieCharacter::PlayTurn()
|
|
||||||
{
|
{
|
||||||
bTurning = true;
|
FRotator rNewRotation = FMath::RInterpTo(GetControlRotation(), rDesireRotation, DeltaTime, fTurnSpeed);
|
||||||
if (fControlTurn < 90.f)
|
Controller->SetControlRotation(rNewRotation);
|
||||||
{
|
|
||||||
TurnTimeline.PlayFromStart();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fControlTurn = 0.f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
@ -52,6 +52,7 @@ protected:
|
|||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
void Move(const FInputActionValue& Value);
|
void Move(const FInputActionValue& Value);
|
||||||
|
void CanTurn(const FInputActionValue& Value);
|
||||||
//void Crouch(const FInputActionValue& Value);
|
//void Crouch(const FInputActionValue& Value);
|
||||||
void RestartLevel();
|
void RestartLevel();
|
||||||
|
|
||||||
@ -70,28 +71,10 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||||
float fAcceleration = .001f;
|
float fAcceleration = .001f;
|
||||||
|
|
||||||
void RotateCharacter();
|
bool bCanTurn = false;
|
||||||
bool bStraight = true;
|
FRotator rDesireRotation = FRotator(0.f, 0.f, 0.f);
|
||||||
int iSideTurn = 1;
|
|
||||||
|
|
||||||
// Properties for the timeline to turn right
|
|
||||||
UFUNCTION()
|
|
||||||
void ControlTurning();
|
|
||||||
UFUNCTION()
|
|
||||||
void SetState();
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||||
UCurveFloat* TurnCurve;
|
float fTurnSpeed = 10.f;
|
||||||
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;
|
|
||||||
|
|
||||||
void Die();
|
void Die();
|
||||||
|
|
||||||
@ -99,11 +82,8 @@ private:
|
|||||||
|
|
||||||
void MoveForwardConstant(float DeltaTime);
|
void MoveForwardConstant(float DeltaTime);
|
||||||
|
|
||||||
void PlayTurn();
|
|
||||||
|
|
||||||
float fControlTurn = 0.f;
|
|
||||||
float fPrevCurvValue = 0.f;
|
|
||||||
|
|
||||||
bool bDied = false;
|
bool bDied = false;
|
||||||
|
|
||||||
|
void TurnCorner(float DeltaTime);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user