3D - Align Object To Ground Normal


Hi there!

I am trying to align a game object to the ground it is on. I have raycast down and got the normal that would point in the right direction.

I believe I need to use vmath.quat_from_to(v1,v2) to align them.

How do I get the object’s “up” vector (which goes to v1 in the equation)?

Thank you for your time and help.


1 Like


This should work to get the local up vector:

local rot = go.get_rotation()
local up = vmath.rotate(rot, vmath.vector3(0, 0, 1))

But I believe using that will give you the change in rotation. If you just want to set the rotation on the object you should be able to use the same (0, 0, 1) “up” vector as the “from” vector (v1) and the normal as v2.



Thank you Ross! That worked (changed your vector to 0,1,0 for up).

I had a feeling there was a simple, elegant solution to this.

Much appreciated!