SetPedLookAt: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Expanding of the example)
Line 24: Line 24:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onClientLookAtRender()
function onClientLookAtRender()
     local rotcam = math.rad (360 - getPedCameraRotation (localPlayer))
     for _, player in ipairs ( getElementsByType ( "player", root, true ) ) do
    local xpos,ypos,zpos = getPedBonePosition (localPlayer, 8)
        local rotcam = math.rad ( 360 - getPedCameraRotation ( player ) )
    local xlook,ylook,zlook = xpos - 300*math.sin(rotcam), ypos + 300*math.cos(rotcam), zpos
        local xpos, ypos, zpos = getPedBonePosition ( player, 8 )
    setPedLookAt (localPlayer, xlook, ylook, zlook, -1)
        local xlook, ylook, zlook = xpos - 300 * math.sin( rotcam ), ypos + 300 * math.cos( rotcam ), zpos
        setPedLookAt ( player, xlook, ylook, zlook )
    end
end
end
addEventHandler ("onClientRender", root, onClientLookAtRender)
addEventHandler ( "onClientRender", root, onClientLookAtRender )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 12:47, 29 July 2014

Makes a ped turn his head and look at a specific world position or element.

Syntax

bool setPedLookAt ( ped thePed, float x, float y, float z [, int time = 3000 [, int blend = 1000 ], element target = nil ] )

Required Arguments

  • thePed: the ped to change the lookat of.
  • x: the x coordinate of the world position to look at.
  • y: the y coordinate of the world position to look at.
  • z: the z coordinate of the world position to look at.

Optional Arguments

  • time: the time, in milliseconds, during which the ped will look at the target. Once this time has elapsed, he will look ahead again like before the function was applied. A time of 0 will immediately stop any lookat. A negative time will make the ped look at the target indefinitely.
  • blend: the time, in milliseconds, during which the look will blend.
  • target: if this argument is specified, the position arguments will be ignored and the ped's gaze will follow the specified element instead. Can be a player, a vehicle, another ped etc.

Example

This example makes player to always see where the camera points at.

Click to collapse [-]
Client
function onClientLookAtRender()
    for _, player in ipairs ( getElementsByType ( "player", root, true ) ) do
        local rotcam = math.rad ( 360 - getPedCameraRotation ( player ) )
        local xpos, ypos, zpos = getPedBonePosition ( player, 8 )
        local xlook, ylook, zlook = xpos - 300 * math.sin( rotcam ), ypos + 300 * math.cos( rotcam ), zpos
        setPedLookAt ( player, xlook, ylook, zlook )
    end
end
addEventHandler ( "onClientRender", root, onClientLookAtRender )

See Also