Lukkaz Posted July 7, 2011 Posted July 7, 2011 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!
JR10 Posted July 7, 2011 Posted July 7, 2011 This event is triggered each time the user moves the mouse on top of a GUI element.
Lukkaz Posted July 7, 2011 Author Posted July 7, 2011 No that's onClientMouseMove like I said it works but I want it so the player can rotate at a still state.
JR10 Posted July 7, 2011 Posted July 7, 2011 Oh, you are right i didn't pay attention, if i understand you correctly you want to rotate the ped on cursor move check the superman resource.
Castillo Posted July 7, 2011 Posted July 7, 2011 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.
Lukkaz Posted July 7, 2011 Author Posted July 7, 2011 it works now the only thing left is moving the verticle axis. Looking up and down. I will try to play around with it but any help again is appreciated.
BinSlayer1 Posted July 8, 2011 Posted July 8, 2011 do you actually need to see the cursor for this to work? I mean, did you use showCursor(true) ?
MTA Team qaisjp Posted July 8, 2011 MTA Team Posted July 8, 2011 Actually, what i think you should do is not go according to mouse movement but go according to the camera matrix. That way it is more accurate and doesnt occur when the mouse is visible.
Lukkaz Posted July 8, 2011 Author Posted July 8, 2011 Well I am developing a FP view for players so they can still aim their gun ect. what would be the best way?
CowTurbo Posted July 9, 2011 Posted July 9, 2011 get ped head position, and set camera matrix to the x,y,z on client pre render
Buffalo Posted July 9, 2011 Posted July 9, 2011 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)
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