Added Temp Hover Bike and Implemented Lean Functionality
This commit is contained in:
parent
50650aa796
commit
3354a804cb
BIN
EndlessVendetta/Content/Ships/BP_SpaceShip.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Ships/BP_SpaceShip.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/Ships/LandingZone.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Ships/LandingZone.uasset
(Stored with Git LFS)
Binary file not shown.
@ -4,6 +4,9 @@
|
||||
#include "SpaceShip.h"
|
||||
|
||||
#include "Components/ArrowComponent.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
|
||||
// Sets default values
|
||||
ASpaceShip::ASpaceShip()
|
||||
@ -32,12 +35,32 @@ void ASpaceShip::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
BikeParentComp = Cast<USpringArmComponent>(GetComponentByClass(USpringArmComponent::StaticClass()));
|
||||
|
||||
PlayersCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
|
||||
PlayersController = PlayersCharacter->GetController();
|
||||
TArray<UActorComponent*> SeatComps = GetComponentsByTag(UArrowComponent::StaticClass(), FName("Seat"));
|
||||
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
|
||||
void ASpaceShip::Tick(float DeltaTime)
|
||||
{
|
||||
@ -45,7 +68,8 @@ void ASpaceShip::Tick(float DeltaTime)
|
||||
|
||||
PlayersCharacter->SetActorLocation(SeatComponent->GetComponentLocation());
|
||||
PlayersController->SetControlRotation(GetActorRotation());
|
||||
|
||||
BikeSwayBasedOnAcc(DeltaTime);
|
||||
|
||||
SightCheck();
|
||||
}
|
||||
|
||||
@ -64,6 +88,8 @@ void ASpaceShip::PlayerInteracting()
|
||||
|
||||
void ASpaceShip::MoveShip(FVector2D MovementVector)
|
||||
{
|
||||
MovementVec = MovementVector;
|
||||
GetWorld()->GetTimerManager().SetTimer(BikeLeanResetTimer, this, &ASpaceShip::ResetBikeLean, 0.2f);
|
||||
// Get ships direction vectors, and ignore their pitch
|
||||
FVector ForwardVector = GetActorForwardVector();
|
||||
ForwardVector.Z = 0;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "LandingZone.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
|
||||
#include "SpaceShip.generated.h"
|
||||
|
||||
@ -21,10 +22,21 @@ class ENDLESSVENDETTA_API ASpaceShip : public ACharacter
|
||||
|
||||
void SightCheck();
|
||||
|
||||
void BikeSwayBasedOnAcc(float DeltaTime);
|
||||
|
||||
FVector2D MovementVec;
|
||||
USpringArmComponent* BikeParentComp;
|
||||
FTimerHandle BikeLeanResetTimer;
|
||||
void ResetBikeLean()
|
||||
{
|
||||
MovementVec.X = 0;
|
||||
MovementVec.Y = 0;
|
||||
}
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
|
||||
public:
|
||||
// Sets default values for this pawn's properties
|
||||
ASpaceShip();
|
||||
|
Loading…
Reference in New Issue
Block a user