can you give me a script example?
Example:
ped = createPed(0, getElementPosition(localPlayer))
addEventHandler("onClientRender", root,
function()
local x, y, z = getElementPosition(localPlayer)
local tx, ty, tz = getElementPosition(ped)
local dis = getDistanceBetweenPoints2D(x, y, tx, ty)
if dis > 2 then
setPedControlState(ped, "forwards", true)
else
setPedControlState(ped, "forwards", false)
end
setPedRotation(ped, findRotation(tx, ty, x, y))
end)
function findRotation(x1,y1,x2,y2)
local t = -math.deg(math.atan2(x2-x1,y2-y1))
if t < 0 then t = t + 360 end
return t
end