diff --git a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp index 80d06c2f..2516e7bf 100644 --- a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.cpp @@ -71,18 +71,40 @@ void ASpaceShip::BikeElevationPhysics(float DeltaTime) { FHitResult OutHit; FCollisionQueryParams CollisionQueryParams; + double HighestElevationPoint = -99999999; 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); + if (GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_WorldStatic, CollisionQueryParams)) + { + HighestElevationPoint = OutHit.Location.Z; + } 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); + if (GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_WorldStatic, CollisionQueryParams) && OutHit.Distance != 0) + { + HighestElevationPoint = OutHit.Location.Z; + UE_LOG(LogTemp, Warning, TEXT("valid point")); + } DrawDebugPoint(GetWorld(), OutHit.Location, 50, FColor::Green); DrawDebugLine(GetWorld(), LT_Start, LT_End, FColor::Green, false, -1, 0, 5); + if (HighestElevationPoint <= -99999998) + { + float GravityAcc = 9.81 * DeltaTime; + CurrentFallSpeed += CurrentFallSpeed < TerminalFallSpeed ? GravityAcc : 0; + CurrentFallSpeed = FMath::Clamp(CurrentFallSpeed, -TerminalFallSpeed, TerminalFallSpeed); + FVector NewLoc = GetActorLocation(); + NewLoc.Z -= CurrentFallSpeed; + SetActorLocation(NewLoc, true); + return; + } + if (CurrentFallSpeed > 0) + { + CurrentFallSpeed = 0; + } } // Called every frame diff --git a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h index 60337646..95beb1b4 100644 --- a/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h +++ b/EndlessVendetta/Source/EndlessVendetta/SpaceShip/SpaceShip.h @@ -26,6 +26,8 @@ class ENDLESSVENDETTA_API ASpaceShip : public ACharacter void BikeElevationPhysics(float DeltaTime); TMap MovementOffsetForLT; + float CurrentFallSpeed = 0; + float TerminalFallSpeed = 100; FVector2D MovementVec; USpringArmComponent* BikeParentComp;