setPedLookAt
Client-side
Server-side
Shared
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
Makes a ped turn his head and look at a specific world position or element.
Note
Avoid calling setPedLookAt every frame as this can cause bugs like being invincible to burning.
Important
For remote players, you have to use setPedAimTarget before setPedLookAt.
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
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- time (default: 3000 [, int blend = 1000 ]): 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 (default: nil): 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.
Returns
- bool: value
Code Examples
shared
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 usetriggerLatentServerEventandtriggerLatentClientEventfunctions.
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)endsetTimer(pedLookAt, 120, 0)Issues
| ID | Description |
|---|---|
| 509 | setPedLookAt does not work for remote players |
| 626 | setPedLookAt cancels damage done by any sort of fire |
See Also
Ped Functions
- addPedClothes
- canPedBeKnockedOffBike
- createPed
- getPedAmmoInClip
- getPedAnalogControlState
- getPedAnimation
- getPedArmor
- getPedBonePosition
- getPedCameraRotation
- getPedClothes
- getPedContactElement
- getPedControlState
- getPedFightingStyle
- getPedGravity
- getPedMoveState
- getPedOccupiedVehicle
- getPedOccupiedVehicleSeat
- getPedOxygenLevel
- getPedSimplestTask
- getPedStat
- getPedTarget
- getPedTargetCollision
- getPedTargetEnd
- getPedTargetStart
- getPedTask
- getPedTotalAmmo
- getPedVoice
- getPedWalkingStyle
- getPedWeapon
- getPedWeaponMuzzlePosition
- getPedWeaponSlot
- getValidPedModels
- givePedWeapon
- isPedBleeding
- isPedChoking
- isPedDead
- isPedDoingGangDriveby
- isPedDoingTask
- isPedDucked
- IsPedFootBloodEnabled
- isPedHeadless
- isPedInVehicle
- isPedOnGround
- isPedReloadingWeapon
- isPedTargetingMarkerEnabled
- isPedWearingJetpack
- killPed
- playPedVoiceLine
- reloadPedWeapon
- removePedClothes
- removePedFromVehicle
- resetPedVoice
- setPedAimTarget
- setPedAnalogControlState
- setPedAnimation
- setPedAnimationProgress
- setPedAnimationSpeed
- setPedArmor
- setPedBleeding
- setPedCameraRotation
- setPedCanBeKnockedOffBike
- setPedChoking
- setPedControlState
- setPedDoingGangDriveby
- setPedEnterVehicle
- setPedExitVehicle
- setPedFightingStyle
- setPedFootBloodEnabled
- setPedGravity
- setPedHeadless
- setPedLookAt
- setPedOxygenLevel
- setPedStat
- setPedTargetingMarkerEnabled
- setPedVoice
- setPedWalkingStyle
- setPedWeaponSlot
- setPedWearingJetpack
- warpPedIntoVehicle