From a517eeb5b8f8871b769ab36d03dca1d45cd66d40 Mon Sep 17 00:00:00 2001 From: Rafal Swierczek Date: Sun, 25 Feb 2024 14:56:58 +0000 Subject: [PATCH] Implemented Dynamic Ground Checks Based on Movement Input --- .../Architecture/Floor_400x400.uasset | 4 ++-- .../HDRI/HDRI_Epic_Courtyard_Daylight.uasset | 4 ++-- .../EndlessVendetta/SpaceShip/SpaceShip.cpp | 23 ++++++++++++++++++- .../EndlessVendetta/SpaceShip/SpaceShip.h | 3 +++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset index 23927787..c2a34afc 100644 --- a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset +++ b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:09965370bba7fa07725b137e66efd7554d16b1c427c51ebab8e7f82e2f0a8355 -size 14831 +oid sha256:4c0ecf0ac0702cc2bd355ec050232a61c49e10f102448efbeb735a51824adef6 +size 14948 diff --git a/EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset b/EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset index 0f990580..45c1d773 100644 --- a/EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset +++ b/EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bc35eb2d43a47427d30aba0196f9eac90d089dd3abca319528c5d25c83510d0d -size 72364642 +oid sha256:8ed6514d622002de71d7aff211f2be020111c265df5ccf17b9d8be0aea7e9c67 +size 66790690 diff --git a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp index 35dbc267..80d06c2f 100644 --- a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp @@ -5,7 +5,6 @@ #include "Components/ArrowComponent.h" #include "GameFramework/CharacterMovementComponent.h" -#include "Kismet/GameplayStatics.h" #include "Kismet/KismetMathLibrary.h" // Sets default values @@ -13,6 +12,9 @@ ASpaceShip::ASpaceShip() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; + MovementOffsetForLT.Add(-1.f, -400); + MovementOffsetForLT.Add(0.f, 0); + MovementOffsetForLT.Add(1.f, 400); } void ASpaceShip::SightCheck() @@ -65,6 +67,24 @@ void ASpaceShip::BikeSwayBasedOnAcc(float DeltaTime) BikeParentComp->SetRelativeRotation(BikeRelativeRot); } +void ASpaceShip::BikeElevationPhysics(float DeltaTime) +{ + FHitResult OutHit; + FCollisionQueryParams CollisionQueryParams; + CollisionQueryParams.AddIgnoredActor(this); + FVector LT_Start = GetActorLocation(); + LT_Start.Z += 150; + FVector LT_End = LT_Start + FVector(0, 0, -450); + GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_WorldStatic, CollisionQueryParams); + DrawDebugPoint(GetWorld(), OutHit.Location, 50, FColor::Red); + DrawDebugLine(GetWorld(), LT_Start, LT_End, FColor::Red, false, -1, 0, 5); + LT_Start = UKismetMathLibrary::TransformLocation(GetActorTransform(), FVector(MovementOffsetForLT[MovementVec.Y] ,MovementOffsetForLT[MovementVec.X], 150)); + LT_End = LT_Start + FVector(0, 0, -600); + GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_WorldStatic, CollisionQueryParams); + DrawDebugPoint(GetWorld(), OutHit.Location, 50, FColor::Green); + DrawDebugLine(GetWorld(), LT_Start, LT_End, FColor::Green, false, -1, 0, 5); +} + // Called every frame void ASpaceShip::Tick(float DeltaTime) { @@ -73,6 +93,7 @@ void ASpaceShip::Tick(float DeltaTime) PlayersCharacter->SetActorLocation(SeatComponent->GetComponentLocation()); PlayersController->SetControlRotation(GetActorRotation()); BikeSwayBasedOnAcc(DeltaTime); + BikeElevationPhysics(DeltaTime); SightCheck(); } diff --git a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h index 87ee3d63..60337646 100644 --- a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h +++ b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h @@ -24,6 +24,9 @@ class ENDLESSVENDETTA_API ASpaceShip : public ACharacter void BikeSwayBasedOnAcc(float DeltaTime); + void BikeElevationPhysics(float DeltaTime); + TMap MovementOffsetForLT; + FVector2D MovementVec; USpringArmComponent* BikeParentComp; FTimerHandle BikeLeanResetTimer;