tm.coords
Vector and rotation helpers. Shared. Angles are degrees, as in GTA.
| Function | Notes |
|---|---|
cross(a, b) | Cross product of two vector3. |
dot(a, b) | Dot product. |
normalize(vector) | Scales a vector3 to length 1. A zero vector, or anything that is not a vector3, is returned unchanged. |
lerp(a, b, t) | a + t * (b - a) with t clamped to 0..1. |
getDirection(heading) | Flat direction of a heading: (cos, sin, 0) of the angle. |
fromRotation(rotation) | Unit vector for a rotation vector3 (pitch in x, yaw in z). |
rotationToDirection(rotation) | The direction a GTA rotation faces. |
toRotation(direction, method) | Direction to rotation. Method 1: yaw only for a camera on a flat direction, returns (0, 0, yaw - 90) (pitch is always 0). Method 2: orients an object so its X axis follows a surface normal (placing on walls, floors and ceilings). A normal parallel to up returns (0, 0, 0) (or (180, 0, 0) for a downward normal) instead of NaN. Any other method errors. |
toVec(table) | Converts { x, y }, { x, y, z } or { x, y, z, w | h | heading | head } to a vector2, vector3 or vector4. A value without an x field is returned as is. |
lua
local normal = tm.coords.normalize(hitPoint - origin)
local rotation = tm.coords.toRotation(normal, 2)
SetEntityRotation(object, rotation.x, rotation.y, rotation.z, 2, true)