Best function in Unreal Engine Kismet Math Library you’ll ever know. You can find Project Vector on to Plane in Kismet Math Library. Don’t confuse this with Project Vector on to Normal which does something more radical.
Plane basically means 360 degrees on plane or aligned surface, where normal means only forward or inverted FVector(1.0, 0.0, 0.0) / FVector(-1.0, 0.0, 0.0).
For example if you want to align forward vector from camera to ground level so you can use that vector to move character forward or backward on ground level.
Camera has Pitch angle which can make the vector point up and down. What Project Vector on to Plane does, is that it gets rid of that pitch angle. And now you have vector which is aligned to ground level and includes Yaw angle of Camera. And then you can put it in “Make Rot From” node and get rotation.
What does it do?
It aligns direction vector to a plane.
List of things you can do with it
- Align camera movement to a plane or surface
- Align any movement to flat surface on any angle
- Align something to direction of gravity
- Measure Pitch, Yaw or Roll angles (dot product and UKismetMathLibrary::DegAcos) align 2 vectors on same plane and dot product them. It’s usually missing Sign (+/-) but you can get that with cross product or dot producting right vector.
- Rotate something on surface or axis.
FTransform T = GetActorTransform();
FVector forward_v = UKismetMathLibrary::InverseTransformDirection(T, SpringArmComp->GetForwardVector());
// #include "Kismet/KismetMathLibrary.h"
UKismetMathLibrary::ProjectVectorOnToPlane(forward_v, FVector(0.0, 0.0, 1.0));
Project Point On To Plane function
Also worth to mention this function too, it basically does the same thing but for vector location.
UKismetMathLibrary::ProjectPointOnToPlane
Example – Align Camera Movement to surface
Green plane is Plane Normal parameter (Z axis). Arrow is aligned direction vector from Forward Vector of Camera.
This is how you can align actor rotation. You should use Make Rot from XY (from two vectors), double align is better. You can use up vector for Plane Normal parameter.
How you can add actor movement.
Example – Measure Angles
This is how you can measure angles with dot product. Two direction vectors into dot product and Inverted cosine (degrees out).
Sometimes the sign is missing (+/-) so use cross product and third direction vector.
And of course you can align direction vectors before they are going in dot product.