Jump to content

moving still ped with cursor?


Lukkaz

Recommended Posts

Hey everyone I am in need of a little help. As you know by playing mta when you run you can rotate the player with moving the mouse. However when you move the mouse when your sitting still the camera moves around the still ped. My question is how can I make the still ped rotate so his back is always to the person playing the game?

My code so far;

  
addEventHandler( "onClientCursorMove", getRootElement( ), 
    function ( cursorX, cursorY, absoluteX, absoluteY, x,y,z) 
pedday = getLocalPlayer() 
if (getElementVelocity(pedday) <= 0) then 
curX, curY, curZ = getElementRotation(getLocalPlayer()) 
  
setElementRotation(pedday, curX , y, z) 
setPedLookAt(pedday, x, curX , curY, z, -3000) 
end 
end 
) 
  

doesn't currently work, the ped gets messed up when in motion and the mouse is moved. ANy help or ideas is really appreciated thanks guy! :D

Link to comment

Here:

addEventHandler( "onClientCursorMove", getRootElement( ), 
function ( cursorX, cursorY, absoluteX, absoluteY, x,y,z) 
local pedday = getLocalPlayer() 
if (getElementVelocity(pedday) <= 0) then 
local x1,y1,_ = getElementPosition(pedday) 
local r = findRotation(x1,y1,x,y) 
setElementRotation(pedday, 0, 0, r) 
curX, curY, curZ = getElementRotation(pedday) 
setPedLookAt(pedday, x, curX , curY, z, -3000) 
end 
end) 
  
function findRotation(x1,y1,x2,y2) 
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end; 
  return t; 
end 

When I move my mouse it rotates the player acording to where I look at.

Link to comment
Well I am developing a FP view for players so they can still aim their gun ect. what would be the best way?

You can't set aim target for local player, so if you want to shoot while in First Person view, you need a work-around.

When aiming disable your FP script and use following

local x,y,z = getElementPosition( getLocalPlayer() ) 
CamFixBody = createObject (983, x, y, z ) 
attachElements ( CamFixBody, getLocalPlayer(), 0, -0.1, 0.45, 90, 0, 90) 
setElementAlpha( CamFixBody, 0) 
setTimer ( setElementAlpha,1000, 1, getLocalPlayer(), 0) 

This will do well, however, localPlayer should be made then invisible. Also you need to check 'weapon_aim' state and switch scripts when state changes (from your to this work-around piece and vice versa)

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...