SetPedLookAt: Difference between revisions
Jump to navigation
Jump to search
m (Added 'Needs Example' category.) |
Zangomangu (talk | contribs) (Updated issues) |
||
(20 intermediate revisions by 12 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client function}} | {{Client function}} | ||
{{Note|Avoid calling setPedLookAt every frame as this can cause bugs like being invincible to burning.}} | |||
{{Important Note|For remote players, you have to use [https://wiki.multitheftauto.com/wiki/SetPedAimTarget setPedAimTarget] before setPedLookAt.}} | |||
Makes a ped turn his head and look at a specific world position or element. | Makes a ped turn his head and look at a specific world position or element. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool setPedLookAt ( ped thePed, float x, float y, float z [, int time = 3000, element target ] ) | bool setPedLookAt ( ped thePed, float x, float y, float z [, int time = 3000 [, int blend = 1000 ], element target = nil ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 17: | Line 17: | ||
===Optional Arguments=== | ===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. | *'''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. | ||
*'''target:''' if this argument is specified, the position arguments will be | *'''blend:''' the time, in milliseconds, during which the look will blend. | ||
*'''target:''' if this argument is specified, the position arguments will be mean offsets relative to the target and the ped's gaze will follow the specified element instead. Can be a player, a vehicle, another ped etc. | |||
==Example== | |||
This example makes the local player look at where the camera points at. If you want to sync this effect with other players you can use [[triggerLatentServerEvent]] and [[triggerLatentClientEvent]] functions. | |||
<syntaxhighlight lang="lua"> | |||
local screenSize_X, screenSize_Y = guiGetScreenSize() | |||
function pedLookAt() | |||
local x, y, z = getWorldFromScreenPosition(screenSize_X / 2, screenSize_Y / 2, 15) | |||
setPedLookAt(localPlayer, x, y, z, -1, 0) | |||
end | |||
setTimer(pedLookAt, 120, 0) | |||
</syntaxhighlight> | |||
== Issues == | |||
{{Issues| | |||
{{Issue|509|setPedLookAt does not work for remote players}} | |||
{{Issue|626|setPedLookAt cancels damage done by any sort of fire}} | |||
}} | |||
==See Also== | ==See Also== | ||
{{Client ped functions}} | {{Client ped functions}} | ||
Latest revision as of 18:59, 30 January 2022
Important Note: For remote players, you have to use setPedAimTarget before setPedLookAt. |
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 mean offsets relative to the target and the ped's gaze will follow the specified element instead. Can be a player, a vehicle, another ped etc.
Example
This example makes the local player look at where the camera points at. If you want to sync this effect with other players you can use triggerLatentServerEvent and triggerLatentClientEvent functions.
local screenSize_X, screenSize_Y = guiGetScreenSize() function pedLookAt() local x, y, z = getWorldFromScreenPosition(screenSize_X / 2, screenSize_Y / 2, 15) setPedLookAt(localPlayer, x, y, z, -1, 0) end setTimer(pedLookAt, 120, 0)
Issues
Issue ID | Description |
---|---|
#509 | setPedLookAt does not work for remote players |
#626 | setPedLookAt cancels damage done by any sort of fire |
See Also
- canPedBeKnockedOffBike
- getPedAnalogControlState
- getPedAnimation
- getPedBonePosition
- getPedCameraRotation
- getPedControlState
- getPedMoveState
- getPedOxygenLevel
- getPedSimplestTask
- getPedTargetCollision
- getPedTargetEnd
- getPedTargetStart
- getPedTask
- getPedVoice
- getPedWeaponMuzzlePosition
- givePedWeapon
- isPedBleeding
- isPedDoingTask
- isPedReloadingWeapon
- isPedTargetingMarkerEnabled
- setAnalogControlState
- setPedAimTarget
- setPedAnalogControlState
- setPedBleeding
- setPedCameraRotation
- setPedCanBeKnockedOffBike
- setPedControlState
- setPedEnterVehicle
- setPedExitVehicle
- IsPedFootBloodEnabled
- setPedFootBloodEnabled
- setPedLookAt
- setPedOxygenLevel
- setPedTargetingMarkerEnabled
- setPedVoice
- Shared
- addPedClothes
- getPedClothes
- removePedClothes
- createPed
- getPedAmmoInClip
- getPedArmor
- getPedFightingStyle
- getPedOccupiedVehicle
- getPedOccupiedVehicleSeat
- getPedStat
- getPedTarget
- getPedTotalAmmo
- getPedWalkingStyle
- getPedWeapon
- getPedWeaponSlot
- getPedContactElement
- getValidPedModels
- isPedChoking
- isPedDead
- isPedDoingGangDriveby
- isPedDucked
- isPedHeadless
- isPedInVehicle
- isPedOnFire
- isPedOnGround
- isPedWearingJetpack
- killPed
- removePedFromVehicle
- setPedAnimation
- setPedAnimationProgress
- setPedAnimationSpeed
- setPedArmor
- setPedDoingGangDriveby
- setPedFightingStyle
- setPedHeadless
- setPedOnFire
- setPedStat
- setPedWalkingStyle
- setPedWeaponSlot
- warpPedIntoVehicle