WIP in the turn of the character
This commit is contained in:
parent
02723795c3
commit
24edf34abf
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:428d9ef2344016cdbd889195ca121a99f3eae544a690837d2ef3a1418c0f4725
|
||||
size 20641
|
||||
oid sha256:d3dd1c59c26b87fd1cdc3103d29ce7833d5cbd841a008137c0c956a8af5251f9
|
||||
size 21542
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:dc4a19c1ae87566ebbdb231db20b810988e9022fd62025b1932346aed0c81174
|
||||
size 22366
|
||||
oid sha256:37e7daf1431d2c994ad4027c7f1a025693551f04212539b979a231e00c4f5925
|
||||
size 22666
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ac43ad7050cc6e5dc17293828fd264bbef8a47020fe80a0f389ced8086698c2c
|
||||
size 34514
|
||||
oid sha256:a382241647580d65fcb11eaed49b5c9e28ca99e8efd50ddb5f8f7c27bce6d1ae
|
||||
size 35058
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:5b3317be7c9d4042271396c2952f0717b70fcfbf100aa15ff2d131554ae0de06
|
||||
size 30566
|
||||
oid sha256:b90f3c7238a1e632d67ece9f697a0f57b1550011561781496dca82807d5f03b2
|
||||
size 33905
|
||||
|
||||
3
Content/Blueprints/Tiles/BP_TileTurnRight.uasset
Normal file
3
Content/Blueprints/Tiles/BP_TileTurnRight.uasset
Normal file
@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:128870a6a999e250ae12fe9bf93bd5b80915245a672072c449950e09e49c5de4
|
||||
size 32357
|
||||
3
Content/Blueprints/Timelines/TurnCurve.uasset
Normal file
3
Content/Blueprints/Timelines/TurnCurve.uasset
Normal file
@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:076327d6ae0300ac0495c29f30577940ef6738ba70587f3ef74d737ddf9aeb37
|
||||
size 1845
|
||||
@ -16,10 +16,11 @@ void APathGenerator::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (int i = 0; i < iInitialStraightTiles; i++)
|
||||
{
|
||||
AddFloorTile();
|
||||
AddSelectedTile(Tiles[0]);
|
||||
}
|
||||
AddSelectedTile(Tiles[1]);
|
||||
|
||||
}
|
||||
|
||||
@ -31,6 +32,15 @@ void APathGenerator::Tick(float DeltaTime)
|
||||
}
|
||||
|
||||
void APathGenerator::AddFloorTile()
|
||||
{
|
||||
if (Tiles[0] != nullptr)
|
||||
{
|
||||
ATile* GeneratedTile = GetWorld()->SpawnActor<ATile>(Tiles[0], tNextSpawnPoint);
|
||||
tNextSpawnPoint = GeneratedTile->GetAttachTransform();
|
||||
}
|
||||
}
|
||||
|
||||
void APathGenerator::AddSelectedTile(TSubclassOf<class ATile> Tile)
|
||||
{
|
||||
if (Tile != nullptr)
|
||||
{
|
||||
|
||||
@ -24,11 +24,17 @@ public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
/*UPROPERTY(EditAnywhere, Category = "Tiles")
|
||||
TSubclassOf<class ATile> Tile;*/
|
||||
UPROPERTY(EditAnywhere, Category = "Tiles")
|
||||
TSubclassOf<class ATile> Tile;
|
||||
TArray<TSubclassOf<class ATile>> Tiles;
|
||||
UPROPERTY(EditAnywhere, Category = "Tiles")
|
||||
int iInitialStraightTiles = 10;
|
||||
|
||||
UFUNCTION(Category = "Tiles")
|
||||
void AddFloorTile();
|
||||
|
||||
void AddSelectedTile(TSubclassOf<class ATile> Tile);
|
||||
|
||||
FTransform tNextSpawnPoint = FTransform(FVector(90.0f, 1110.0f, 0.0f));
|
||||
};
|
||||
|
||||
@ -65,7 +65,7 @@ void ATile::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* Oth
|
||||
FTimerHandle TimerHandle;
|
||||
|
||||
//GetWorldTimerManager().SetTimer(TimerHandle, this, &ATimeKollapsed_PlayerController::AddWidgetToViewPort, GameOverDelay, false);
|
||||
GetWorldTimerManager().SetTimer(TimerHandle, this, &ATile::test, 2.f, false);
|
||||
GetWorldTimerManager().SetTimer(TimerHandle, this, &ATile::DestroyTile, 2.f, false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "AttachedPoint")
|
||||
FTransform GetAttachTransform();
|
||||
UFUNCTION()
|
||||
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
|
||||
private:
|
||||
void DestroyTile();
|
||||
|
||||
57
Source/EndlessZombie/TileCurve.cpp
Normal file
57
Source/EndlessZombie/TileCurve.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright Jorge Kuijper. All Rights Reserved.
|
||||
|
||||
|
||||
#include "TileCurve.h"
|
||||
#include "ZombieCharacter.h"
|
||||
|
||||
ATileCurve::ATileCurve()
|
||||
{
|
||||
TurnTrigger = CreateDefaultSubobject<UBoxComponent>(TEXT("TurnTrigger"));
|
||||
TurnTrigger->SetupAttachment(SceneComponent);
|
||||
TurnTrigger->SetCollisionProfileName(TEXT("OverlapOnlyPawn"));
|
||||
//TurnTrigger->OnComponentBeginOverlap.AddDynamic(this, &ATileCurve::TurnBeginOverlap);
|
||||
}
|
||||
|
||||
|
||||
void ATileCurve::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
TurnTrigger->OnComponentBeginOverlap.AddDynamic(this, &ATileCurve::TurnBeginOverlap);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ATileCurve::TurnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||
{
|
||||
AZombieCharacter* ZombieCharacter = Cast<AZombieCharacter>(OtherActor);
|
||||
|
||||
if (ZombieCharacter != nullptr)
|
||||
{
|
||||
if (!bWasTriggered)
|
||||
{
|
||||
// Yaw
|
||||
float fYawValue;
|
||||
|
||||
if (bTurnRight && !bTurnLeft)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[ATileCurve::OnBeginOverlapChild] Rotating right"));
|
||||
fYawValue = 90.f;
|
||||
FRotator NewRotation = FRotator(0.f, fYawValue, 0.f);
|
||||
ZombieCharacter->bStraight = false;
|
||||
ZombieCharacter->NewRotation = NewRotation;
|
||||
//ZombieCharacter->RotateCharacter(NewRotation);
|
||||
}
|
||||
else if (!bTurnRight && bTurnLeft)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[ATileCurve::OnBeginOverlapChild] Rotating left"));
|
||||
fYawValue = -90.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("[ATileCurve::OnBeginOverlapChild] You should not be here, check if bTurnRight and bTurnLeft have the same value."))
|
||||
}
|
||||
bWasTriggered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Source/EndlessZombie/TileCurve.h
Normal file
36
Source/EndlessZombie/TileCurve.h
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright Jorge Kuijper. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Tile.h"
|
||||
#include "TileCurve.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class ENDLESSZOMBIE_API ATileCurve : public ATile
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ATileCurve();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UBoxComponent* TurnTrigger;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Turn")
|
||||
bool bTurnRight = true;
|
||||
UPROPERTY(EditAnywhere, Category = "Turn")
|
||||
bool bTurnLeft = false;
|
||||
|
||||
UFUNCTION()
|
||||
virtual void TurnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
bool bWasTriggered = false;
|
||||
};
|
||||
@ -26,7 +26,7 @@ AZombieCharacter::AZombieCharacter()
|
||||
bUseControllerRotationRoll = false;
|
||||
|
||||
// Configure character movement
|
||||
GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...
|
||||
GetCharacterMovement()->bOrientRotationToMovement = false; // Character moves in the direction of input...
|
||||
GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate
|
||||
|
||||
// Note: For faster iteration times these variables, and many more, can be tweaked in the Character Blueprint
|
||||
@ -37,17 +37,28 @@ AZombieCharacter::AZombieCharacter()
|
||||
GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
|
||||
GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;
|
||||
|
||||
|
||||
// Create a camera boom (pulls in towards the player if there is a collision)
|
||||
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
|
||||
CameraBoom->SetupAttachment(RootComponent);
|
||||
CameraBoom->TargetArmLength = 400.f; // The camera follows at this distance behind the character
|
||||
CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
|
||||
CameraBoom->SetWorldLocation(FVector(0.f, 0.f, 180.f));
|
||||
|
||||
// Create a follow camera
|
||||
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
|
||||
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
|
||||
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
|
||||
@ -62,14 +73,35 @@ 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
|
||||
void AZombieCharacter::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
MoveForwardConstant(DeltaTime);
|
||||
|
||||
TurnTimeline.TickTimeline(DeltaTime);
|
||||
|
||||
if (!bTurning)
|
||||
{
|
||||
MoveForwardConstant(DeltaTime);
|
||||
}
|
||||
|
||||
//NewRotation.Yaw += 5.f;
|
||||
//RotateCharacter(a);
|
||||
}
|
||||
|
||||
// Called to bind functionality to input
|
||||
@ -122,8 +154,89 @@ void AZombieCharacter::Move(const FInputActionValue& Value)
|
||||
|
||||
void AZombieCharacter::MoveForwardConstant(float DeltaTime)
|
||||
{
|
||||
FVector vLocation = GetActorLocation();
|
||||
vLocation += GetActorForwardVector() * fBaseSpeed * DeltaTime;
|
||||
SetActorLocation(vLocation);
|
||||
if (bStraight)
|
||||
{
|
||||
FVector vLocation = GetActorLocation();
|
||||
vLocation += GetActorForwardVector() * fBaseSpeed * DeltaTime;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AZombieCharacter::PlayTurn()
|
||||
{
|
||||
bTurning = true;
|
||||
if (fControlTurn < 90.f)
|
||||
{
|
||||
TurnTimeline.PlayFromStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
fControlTurn = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
void AZombieCharacter::UpdateDirection(int i)
|
||||
{
|
||||
iCurrentDirection += i;
|
||||
if (iCurrentDirection > mDirections.Num())
|
||||
{
|
||||
iCurrentDirection = 0;
|
||||
}
|
||||
else if (iCurrentDirection < 0)
|
||||
{
|
||||
iCurrentDirection = mDirections.Num();
|
||||
}
|
||||
|
||||
vCurrentDirection = mDirections[iCurrentDirection];
|
||||
}
|
||||
|
||||
void AZombieCharacter::RotateCharacter()
|
||||
{
|
||||
FRotator CurrentRotation = GetActorRotation();
|
||||
PlayTurn();
|
||||
UE_LOG(LogTemp, Warning, TEXT("Girao"));
|
||||
//Controller->SetControlRotation(NewRotation + CurrentRotation);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
fControlTurn += fVal;
|
||||
|
||||
if (fControlTurn <= 90.f)
|
||||
{
|
||||
FRotator CurrentRotation = Controller->GetControlRotation();
|
||||
CurrentRotation.Yaw += fVal;
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AZombieCharacter::SetState()
|
||||
{
|
||||
bReadyState = true;
|
||||
bTurning = false;
|
||||
bStraight = true;
|
||||
UE_LOG(LogTemp, Warning, TEXT("[AZombieCharacter::SetState] Set state"));
|
||||
}
|
||||
@ -5,6 +5,7 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "InputActionValue.h"
|
||||
#include "Components/TimelineComponent.h"
|
||||
#include "ZombieCharacter.generated.h"
|
||||
|
||||
UCLASS()
|
||||
@ -13,11 +14,11 @@ class ENDLESSZOMBIE_API AZombieCharacter : public ACharacter
|
||||
GENERATED_BODY()
|
||||
|
||||
/** Camera boom positioning the camera behind the character */
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
class USpringArmComponent* CameraBoom;
|
||||
|
||||
/** Follow camera */
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
class UCameraComponent* FollowCamera;
|
||||
|
||||
/** MappingContext */
|
||||
@ -63,8 +64,38 @@ public:
|
||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||
float fBaseSpeed = 100.f;
|
||||
|
||||
void RotateCharacter();
|
||||
bool bStraight = true;
|
||||
FRotator NewRotation = FRotator(0.f, 0.f, 0.f);
|
||||
|
||||
// Properties for the timeline to turn right
|
||||
UFUNCTION()
|
||||
void ControlTurning();
|
||||
UFUNCTION()
|
||||
void SetState();
|
||||
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;
|
||||
|
||||
void UpdateDirection(int i);
|
||||
|
||||
private:
|
||||
|
||||
void MoveForwardConstant(float DeltaTime);
|
||||
|
||||
void PlayTurn();
|
||||
|
||||
float fControlTurn = 0.f;
|
||||
float fPrevCurvValue = 0.f;
|
||||
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user