With this simple bit of code, we are able to move our ped's head ?? in the direction we choose to move the mouse ?️. The only thing i dont like is how the head moves while the ped is aiming around. I need to force the head to look at where i'm aiming. I tried using the weapon muzzle position as the forced lookAt position but i'm not sure why it's not working.
---------------------------
-- Head Moving
---------------------------
local scrX, scrY = guiGetScreenSize ( )
setTimer(
function()
if not isPedAiming(localPlayer) then
local x, y, z = getWorldFromScreenPosition( scrX / 2, scrY / 2, 15)
setPedLookAt(localPlayer, x, y, z, 3000, 1000, nil)
else
local sx, sy, sz = getPedWeaponMuzzlePosition(localPlayer)
setPedLookAt(localPlayer, sx, sy, sz, 0, 0, nil)
end
end, 120, 0)
---------------------------
-- Functions
---------------------------
function isPedAiming (thePedToCheck)
if isElement(thePedToCheck) then
if getElementType(thePedToCheck) == "player" or getElementType(thePedToCheck) == "ped" then
if getPedTask(thePedToCheck, "secondary", 0) == "TASK_SIMPLE_USE_GUN" or isPedDoingGangDriveby(thePedToCheck) then
return true
end
end
end
return false
end