MTA.Castiel Posted March 4, 2023 Share Posted March 4, 2023 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
Moderators IIYAMA Posted March 5, 2023 Moderators Share Posted March 5, 2023 20 hours ago, MTA.Castiel said: tried using the weapon muzzle position as the forced lookAt position Try this one instead: https://wiki.multitheftauto.com/wiki/GetPedTargetEnd Note: The returned values can be nil. Link to comment
Shady1 Posted March 7, 2023 Share Posted March 7, 2023 (edited) --------------------------- -- 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 March 7, 2023 by Shady1 1 Link to comment
MTA.Castiel Posted March 7, 2023 Author Share Posted March 7, 2023 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
Shady1 Posted March 8, 2023 Share Posted March 8, 2023 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now