How would rotate an entity to face a 3d vector?
I know how to do this in 2d but I don't know how to do it in a 3d world
yaw = math.atan2(-my_vector.x, my_vector.z) -- radians!
pitch = math.atan2(-my_vector.y, math.sqrt(my_vector.x^2 + my_vector.z^2))
roll = 0
Extex wrote:How would rotate an entity to face a 3d vector?
function dir_to_rot(v,rot)
return {x = (v.x==0 and v.y==0 and v.z==0) and rot.x or math.atan2(v.y,vector.length({x=v.x,y=0,z=v.z})),
y = (v.x==0 and v.z==0) and rot.y or minetest.dir_to_yaw(v),
z=rot.z}
end
Users browsing this forum: No registered users and 4 guests