Player Rotation Left, RIght, Forward, Backwards

Hello I was hoping someone will help me with a math problem.
Doing traces from a melee weapon I need to figure out what side the player was struck from.
To determine what hit animation to play, I realize it may be trivial to some but am stuck. :stuck_out_tongue:

I get the the following data from the HitResult for the trace.


HitResult.ImpactPoint; // Location
Location.Rotation(); // Roation

// Get Direction and Distance
FVector Direction(ForceInitToZero);
float Distance = 0.f;
Location.ToDirectionAndLength(Direction, Distance);


I can get the same data for the player but am unsure what to do.
Google seems little help at this point.

Thanks for any help!

Cheers!

You could get the TraceStart from your trace, get the look at direction, and compare the angle of that against the rotation of the actor youโ€™re hitting?

You could try and get the angle between the impact point and the actors forward vector. That could give you where the player was hit.
I did this once for line trace (just a note that my actors were always on xy plane, they only rotated around the z axis) and this worked for me.


FVector c = FVector::CrossProduct(HitResult.ImpactPoint - HitResult.Actor->GetActorLocation(), HitResult.Actor->GetActorForwardVector());

Thank you guys i will give it a try and report back.
Cheers!

Edit: Ok so this is the solution i came up with in the end.
Thank you for stearing me in the right direction.


// Get the local location for where player was hit.
const FVector HitActorLocation = HitResult.GetActor()->GetActorLocation();
const FRotator HitActorRotation = HitResult.GetActor()->GetActorRotation();
FVector LocalSpaceHitLocation = HitActorRotation.UnrotateVector(HitResult.ImpactPoint - HitActorLocation);

// Normalize Result
/* X >= 0.0 == Forward, X < 0.0 == Backward */
/* Y >= 0.0 == Right, Y < 0.0 == Left */
LocalSpaceHitLocation.Normalize();