Implemented Custom Gravity for Hover Bike

This commit is contained in:
Rafal Swierczek 2024-02-25 16:17:25 +00:00
parent 614d1c7219
commit dca168ca3d
2 changed files with 26 additions and 2 deletions

View File

@ -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

View File

@ -26,6 +26,8 @@ class ENDLESSVENDETTA_API ASpaceShip : public ACharacter
void BikeElevationPhysics(float DeltaTime);
TMap<float, double> MovementOffsetForLT;
float CurrentFallSpeed = 0;
float TerminalFallSpeed = 100;
FVector2D MovementVec;
USpringArmComponent* BikeParentComp;