Implemented Custom Gravity for Hover Bike
This commit is contained in:
parent
614d1c7219
commit
dca168ca3d
@ -71,18 +71,40 @@ void ASpaceShip::BikeElevationPhysics(float DeltaTime)
|
|||||||
{
|
{
|
||||||
FHitResult OutHit;
|
FHitResult OutHit;
|
||||||
FCollisionQueryParams CollisionQueryParams;
|
FCollisionQueryParams CollisionQueryParams;
|
||||||
|
double HighestElevationPoint = -99999999;
|
||||||
CollisionQueryParams.AddIgnoredActor(this);
|
CollisionQueryParams.AddIgnoredActor(this);
|
||||||
FVector LT_Start = GetActorLocation();
|
FVector LT_Start = GetActorLocation();
|
||||||
LT_Start.Z += 150;
|
LT_Start.Z += 150;
|
||||||
FVector LT_End = LT_Start + FVector(0, 0, -450);
|
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);
|
DrawDebugPoint(GetWorld(), OutHit.Location, 50, FColor::Red);
|
||||||
DrawDebugLine(GetWorld(), LT_Start, LT_End, FColor::Red, false, -1, 0, 5);
|
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_Start = UKismetMathLibrary::TransformLocation(GetActorTransform(), FVector(MovementOffsetForLT[MovementVec.Y] ,MovementOffsetForLT[MovementVec.X], 150));
|
||||||
LT_End = LT_Start + FVector(0, 0, -600);
|
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);
|
DrawDebugPoint(GetWorld(), OutHit.Location, 50, FColor::Green);
|
||||||
DrawDebugLine(GetWorld(), LT_Start, LT_End, FColor::Green, false, -1, 0, 5);
|
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
|
// Called every frame
|
||||||
|
@ -26,6 +26,8 @@ class ENDLESSVENDETTA_API ASpaceShip : public ACharacter
|
|||||||
|
|
||||||
void BikeElevationPhysics(float DeltaTime);
|
void BikeElevationPhysics(float DeltaTime);
|
||||||
TMap<float, double> MovementOffsetForLT;
|
TMap<float, double> MovementOffsetForLT;
|
||||||
|
float CurrentFallSpeed = 0;
|
||||||
|
float TerminalFallSpeed = 100;
|
||||||
|
|
||||||
FVector2D MovementVec;
|
FVector2D MovementVec;
|
||||||
USpringArmComponent* BikeParentComp;
|
USpringArmComponent* BikeParentComp;
|
||||||
|
Loading…
Reference in New Issue
Block a user