[SOLVED] Rotate a vector to make it into the up/forward vector plane

Hi, I have a normal that I need to put into the same plane as the one defined by the up and forward vectors of an actor. Intuitively, I need to discard the “side” components of my normal to get only its pitch, and this to work whatever the current rotation of my actor.
In math this means I need to have a quaternion whose vector is the forward vector, and rotate my normal a certain angle around this forward vector. I am not sure how to determine this angle. This can’t be the angle between my normal and the up or forward vectors, for this my normal would already need to be in the plane of one or the other. Remember I need to determine the angle whatever the current rotation of the actor is.

I have found the following solution but I don’t like it much, there should be a way to do this with quaternions and not use the actor transform, please let me know if you know a better way!



// transform normals into a reference space where they can be compared to actor with no rotation
FTransform actorTransform = character->GetActorTransform();
FVector transNormal = actorTransform.InverseTransformVectorNoScale(normal);

// cancel Y as we are interested into the X/Z plane only
transNormal.Y = 0.f;

// put the normal back into the current actor rotation space
transNormal = actorTransform.TransformVectorNoScale(transNormal);


Not sure if I understand you correctly. Where your normal (direction vector) is coming from? If direction vector is in the world space, then you can create new transform by using forward and up vectors as it’s basis, then using this transform, inverse-transform direction vector. Resulting vector will be in local space defined by forward and up vectors.

Ahh, I see now - was writing reply when you posted. Perhaps just Project To Plane will do what you need.

@BoredEngineer: UKismetMathLibrary::ProjectVectorOnToPlane() is doing exactly what I need, thanks a lot!