- Documentation
- Shared functions
- findRotation
Function
findRotation
Returns the rotation angle from point 1 towards point 2, in degrees, in the same convention as setElementRotation (0 = north).
Syntax
float findRotation(float x1, float y1, float x2, float y2)Arguments
x1float- X of point 1.
y1float- Y of point 1.
x2float- X of point 2.
y2float- Y of point 2.
Returns
The angle in degrees, 0-360.
Example
local function facePlayer(ped, player)
local px, py = getElementPosition(ped)
local tx, ty = getElementPosition(player)
setElementRotation(ped, 0, 0, findRotation(px, py, tx, ty))
end