Jump to content

PED Head Moving


Recommended Posts

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

 

Link to comment
---------------------------
-- 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)
        local ex, ey, ez = getPedTargetEnd(localPlayer)
        if ex and ey and ez then
            setPedLookAt(localPlayer, ex, ey, ez, 0, 0, nil)
        end
    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

i tried to do something but i hope it works, i didn't test it

Edited by Shady1
  • Like 1
Link to comment

Hi Shady, thanks for getting back to me on this one, much appreciated. ? I've tested the code it but it still hasn't done the trick. I have however managed to get it working with a different method, i just needed more time to work it out. 
 

---------------------------
-- Head Moving
---------------------------

local scrX, scrY = guiGetScreenSize( )
  setTimer( function( ) 
      if not ( getKeyState ( "mouse2" ) == true ) then
      local x, y, z = getWorldFromScreenPosition( scrX / 2, scrY / 2, 15 )
    setPedLookAt( localPlayer, x, y, z, 3000, 1000, nil )
  end
end, 100, 0 )

function focusOnTarget( button, press )
  if isPedInVehicle( localPlayer ) then return end
  if ( press and button == "mouse2" ) then
    setPedLookAt( localPlayer, 0, 0, 0, 0, 0, nil )
  end
end
addEventHandler( "onClientKey", root, focusOnTarget )

 

Link to comment
17 hours ago, MTA.Castiel said:

Hi Shady, thanks for getting back to me on this one, much appreciated. ? I've tested the code it but it still hasn't done the trick. I have however managed to get it working with a different method, i just needed more time to work it out. 
 

---------------------------
-- Head Moving
---------------------------

local scrX, scrY = guiGetScreenSize( )
  setTimer( function( ) 
      if not ( getKeyState ( "mouse2" ) == true ) then
      local x, y, z = getWorldFromScreenPosition( scrX / 2, scrY / 2, 15 )
    setPedLookAt( localPlayer, x, y, z, 3000, 1000, nil )
  end
end, 100, 0 )

function focusOnTarget( button, press )
  if isPedInVehicle( localPlayer ) then return end
  if ( press and button == "mouse2" ) then
    setPedLookAt( localPlayer, 0, 0, 0, 0, 0, nil )
  end
end
addEventHandler( "onClientKey", root, focusOnTarget )

 

ahh to tell you the truth, I didn't understand exactly what you wanted to do, but now I understand what you are trying to do with the code you showed :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...