Added Temp Hover Bike and Implemented Lean Functionality

This commit is contained in:
Rafal Swierczek 2024-02-01 03:58:11 +00:00
parent 50650aa796
commit 3354a804cb
4 changed files with 43 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -4,6 +4,9 @@
#include "SpaceShip.h" #include "SpaceShip.h"
#include "Components/ArrowComponent.h" #include "Components/ArrowComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetMathLibrary.h"
// Sets default values // Sets default values
ASpaceShip::ASpaceShip() ASpaceShip::ASpaceShip()
@ -32,12 +35,32 @@ void ASpaceShip::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
BikeParentComp = Cast<USpringArmComponent>(GetComponentByClass(USpringArmComponent::StaticClass()));
PlayersCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); PlayersCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
PlayersController = PlayersCharacter->GetController(); PlayersController = PlayersCharacter->GetController();
TArray<UActorComponent*> SeatComps = GetComponentsByTag(UArrowComponent::StaticClass(), FName("Seat")); TArray<UActorComponent*> SeatComps = GetComponentsByTag(UArrowComponent::StaticClass(), FName("Seat"));
SeatComponent = Cast<UArrowComponent>(SeatComps[0]); SeatComponent = Cast<UArrowComponent>(SeatComps[0]);
} }
void ASpaceShip::BikeSwayBasedOnAcc(float DeltaTime)
{
float LeanSpeed = 90.f;
float ForwardLeanIncrement = LeanSpeed * DeltaTime * MovementVec.Y;
float RightLeanIncrement = LeanSpeed * DeltaTime * MovementVec.X;
FRotator BikeRelativeRot = BikeParentComp->GetRelativeRotation();
float BikePitch = BikeRelativeRot.Pitch;
float BikeRoll = BikeRelativeRot.Roll;
BikeRelativeRot.Pitch = FMath::Clamp(BikePitch + ForwardLeanIncrement, -5.f, 5.f);
BikeRelativeRot.Roll = FMath::Clamp(BikeRoll + RightLeanIncrement, -30.f, 30.f);
if (MovementVec.Y == 0) BikeRelativeRot.Pitch = BikePitch > 0 ? FMath::Clamp(BikePitch - ((LeanSpeed / 2.f) * DeltaTime), 0.f, 99.f) : FMath::Clamp(BikePitch + ((LeanSpeed / 2.f) * DeltaTime), -99, 0.f);
if (MovementVec.X == 0) BikeRelativeRot.Roll = BikeRoll > 0 ? FMath::Clamp(BikeRoll - ((LeanSpeed / 2.f) * DeltaTime), 0.f, 99.f) : FMath::Clamp(BikeRoll + ((LeanSpeed / 2.f) * DeltaTime), -99, 0.f);
BikeParentComp->SetRelativeRotation(BikeRelativeRot);
}
// Called every frame // Called every frame
void ASpaceShip::Tick(float DeltaTime) void ASpaceShip::Tick(float DeltaTime)
{ {
@ -45,6 +68,7 @@ void ASpaceShip::Tick(float DeltaTime)
PlayersCharacter->SetActorLocation(SeatComponent->GetComponentLocation()); PlayersCharacter->SetActorLocation(SeatComponent->GetComponentLocation());
PlayersController->SetControlRotation(GetActorRotation()); PlayersController->SetControlRotation(GetActorRotation());
BikeSwayBasedOnAcc(DeltaTime);
SightCheck(); SightCheck();
} }
@ -64,6 +88,8 @@ void ASpaceShip::PlayerInteracting()
void ASpaceShip::MoveShip(FVector2D MovementVector) void ASpaceShip::MoveShip(FVector2D MovementVector)
{ {
MovementVec = MovementVector;
GetWorld()->GetTimerManager().SetTimer(BikeLeanResetTimer, this, &ASpaceShip::ResetBikeLean, 0.2f);
// Get ships direction vectors, and ignore their pitch // Get ships direction vectors, and ignore their pitch
FVector ForwardVector = GetActorForwardVector(); FVector ForwardVector = GetActorForwardVector();
ForwardVector.Z = 0; ForwardVector.Z = 0;

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "LandingZone.h" #include "LandingZone.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
#include "GameFramework/SpringArmComponent.h"
#include "SpaceShip.generated.h" #include "SpaceShip.generated.h"
@ -21,10 +22,21 @@ class ENDLESSVENDETTA_API ASpaceShip : public ACharacter
void SightCheck(); void SightCheck();
void BikeSwayBasedOnAcc(float DeltaTime);
FVector2D MovementVec;
USpringArmComponent* BikeParentComp;
FTimerHandle BikeLeanResetTimer;
void ResetBikeLean()
{
MovementVec.X = 0;
MovementVec.Y = 0;
}
protected: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:
// Sets default values for this pawn's properties // Sets default values for this pawn's properties
ASpaceShip(); ASpaceShip();