- Documentation
- Server functions
- setPedLookAt
Function
setPedLookAt
Turns a ped toward the given point and remembers where and for how long it should look. The body turn happens immediately (the ped's heading changes), while the point, time and element are stored for scripts and returned by getPedLookAt; the game does not additionally turn the head. To keep following a target with the eyes use setPedFocus.
Syntax
bool setPedLookAt(ped ped, float x, float y, float z [, int time = 3000, int blend = 1000, element target = nil])Arguments
pedped- A player or an NPC.
xfloat- X coordinate of the point (or a
Vector3in place of x, y, z). yfloat- Y coordinate of the point.
zfloat- Z height of the point.
timeint, optional = 3000- How long to look, in milliseconds.
blendint, optional = 1000- Smooth turn time in ms (stored for scripts).Different type in MTA:SA: element target = nil
targetelement, optional = nil- The element the ped looks at (stored for scripts).Not in MTA:SA
Differences from MTA:SA
- Arguments in a different colour differ from MTA:SA.
In MTA:SA
setPedLookAt(ped thePed, float x, float y, float z, int time = 3000 [, int blend = 1000 ], element target = nil)Returns
true on success.
Example
local x, y, z = getElementPosition(player)
setPedLookAt(guard, x, y, z, 5000)
See also
getPedLookAtReturns the point a ped should look at according to the lastsetPedLookAt, and the time (ingetTickCountunits) until which the look lasts. Returnsfalsewhen nothing was set.setPedFocusMakes an NPC keep looking at a chosen element: the ped turns its whole body toward it, optionally its head too, and follows it as it moves. On the server everyone sees it. On the client it only works in this game and overrides the server's setting;nilbrings back what the server set. Useful for shopkeepers, guards and NPCs in cutscenes.setElementRotationSets the element's rotation in degrees. On the client it turns your own character in the same frame (no teleport) and client objects.