diff --git a/EndlessVendetta/Content/Ships/BP_SpaceShip.uasset b/EndlessVendetta/Content/Ships/BP_SpaceShip.uasset index 71994809..92ea4e0b 100644 --- a/EndlessVendetta/Content/Ships/BP_SpaceShip.uasset +++ b/EndlessVendetta/Content/Ships/BP_SpaceShip.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e278fce27c3ac05506781357ed5235d16e8f371a9ad242cebd374f17c20bb338 -size 37016 +oid sha256:b44f822f5c6482c3351c981ff00819af201f59f73a9f8a4a84e2eb6ba0bd9d72 +size 59373 diff --git a/EndlessVendetta/Content/Ships/LandingZone.uasset b/EndlessVendetta/Content/Ships/LandingZone.uasset index cdffb78b..d8d6f2ba 100644 --- a/EndlessVendetta/Content/Ships/LandingZone.uasset +++ b/EndlessVendetta/Content/Ships/LandingZone.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d996a836e1ad72307a3f43490e4b8ac9958cef1af776de25773aca5e74506822 -size 88748 +oid sha256:dfde55ec08a338b74108a49afc1af5c2f689d323773b9cc4719adcacce033a03 +size 77058 diff --git a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp index a12d3bcf..735a6222 100644 --- a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp @@ -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(GetComponentByClass(USpringArmComponent::StaticClass())); + PlayersCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); PlayersController = PlayersCharacter->GetController(); TArray SeatComps = GetComponentsByTag(UArrowComponent::StaticClass(), FName("Seat")); SeatComponent = Cast(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; diff --git a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h index 78f0ed03..87ee3d63 100644 --- a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h +++ b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h @@ -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();