Hello!
I am trying to do something that should be relatively simple. I have a vector that I want to project onto a plane.
I have the plane normal N that I get as result of a linetrace to the ground. I would expect that projecting my vector onto the plane defined by N, I’d get a vector that is parallel to the ground. But the result is off by quite a bit (see image).
Here’s the code I am using:
FHitResult Hit(1.f);
FCollisionQueryParams CollisionParams;
// Linetrace to the ground (in this case from an Actor's Location)
bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, GetActorLocation(), GetActorLocation() - FVector(0, 0, 200), ECC_Visibility, CollisionParams);
// The vector V I want to project
FVector V = GetCharacterOwner()->GetActorForwardVector();
if (bHit) {
FVector Normal = Hit.Normal.GetSafeNormal();
FVector Projection = FVector::VectorPlaneProject(SlidingAcceleration, Normal2D);
}