quaternion.lookdir
EditReturns a quaternion that looks in a direction. More accurately, it returns a quaternion that rotates from the forward vector (0, 0, -1) to a given direction.
The up vector is used to control the "roll" of the orientation, since there are an infinite number of orientations that look in a given direction.
q = quaternion.lookdir(direction, up)Arguments
| Name | Type | Default | Description |
| direction | vector | The direction to look towards. It does not need to be normalized. | |
| up | number | vector.up | The up vector. It does not need to be normalized. |
Returns
| Name | Type | Description |
| q | quaternion |
A quaternion that rotates from the forward vector to direction.
|
Example
This is very useful for rotating an object to face a target.
local origin = vector(x, y, z) -- the position of the object
local target = vector(tx, ty, tz) -- what it should look at
local rotation = quaternion.lookdir(target - origin)
pass:draw(model, origin, 1, rotation)