Hi, so i am building a hang from ledge/surface system. Where i do a line trace from forward of character (GetActorForwardVector()) and at the hit point i do a downward trace and get the impact point.
So far this works great, but now i am trying to do 5 line traces to the Left and Right of the impact point, i don’t know how would i do that!
This is the data i have to work with:
FVector TargetLocation = Ledge.ForwardHitResult.ImpactPoint;
FVector TargetDirection = Ledge.ForwardHitResult.ImpactNormal;
// Some directional logic so i can
TargetLocation += FVector::LeftVector * 5.0f;
// ^ do this 5 times for 5 different line traces on left side of original location
From the actor’s perspective, right and left of the impact point is very easy: GetActorRightVector() and GetActorRightVector() * -1.f.
I suspect you may want to ‘follow the wall’ though? In which case grab the impact normal, cross it with FVector::UP, and that is your ‘right’ vector (which will be to the left from the character’s point of view).
Wont work well with curved walls of course, and will break down if you hit a perfectly upward facing surface (which I think shouldn’t be possible if your initial trace was with the actor forward vector).
The hit result is generated from a single line trace in forward direction of actor (GetActorForwardVector).
const FRotator Rotation = (CurrentLedge.ForwardHitResult.ImpactNormal * -1).ToOrientationRotator();
// Get right side of the current forward hit impact point
FVector RightDirection = FRotationMatrix(Rotation).GetUnitAxis(EAxis::Y);
// This is the final point in right direction
FVector CapsuleLocation = CurrentLedge.ForwardHitResult.ImpactPoint + RightDirection * 15.0f;
This is what i came up with, it seems to work so far!