Hello, it’s me again.
FCollisionQueryParams Params;
// Ignore the player's pawn
// The hit result gets populated by the line trace
FHitResult Hit;
// Raycast out from the camera, only collide with pawns (they are on the ECC_Pawn collision channel)
FVector Start = thruster->GetComponentLocation();
FVector End = Start + (thruster->GetUpVector() * (traceLength*-1));
bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECC_Pawn, Params);
if (bHit)
{
// Hit.Actor contains a weak pointer to the Actor that the trace hit
FVector step1 = Hit.Location - thruster->GetComponentLocation();
float vectorLength = step1.Size();
float alpha = vectorLength / traceLength;
float step2 = FMath::Lerp(hoverForce, 0.0f, alpha);
FVector downwardForce = Hit.ImpactNormal * step2;
//StaticMeshComponent->AddForceAtLocation(FVector(0, 0, 1) * hoverForce *(1.0f - (Hit.Distance / traceLength)), thruster->GetComponentLocation());
StaticMeshComponent->AddForceAtLocation(downwardForce, thruster->GetComponentLocation());
StaticMeshComponent->SetLinearDamping(inDamping);
StaticMeshComponent->SetAngularDamping(8.0f);
compressionRatio = alpha;
surfaceImpactNormal = Hit.ImpactNormal;
surfaceImpactPoint = Hit.ImpactPoint;
}
The problem is my trace length and debug differs.
If you look at the first picture my trace length is going through the ground. No I don’t want that, I want it to touch the ground, and then push me up.
Second picture:
I am in mid - air and my trace length (the yellow lines) are way longer.
Have I implemented the ray cast wrong?