qaisjp Posted July 15, 2011 Share Posted July 15, 2011 I know that I should use the search bar, but i couldn't find the topic using the search terms I used. So well here it is: The rotation of the ped is where the screen looks at, anyone can help? Link to comment
#Paper Posted July 15, 2011 Share Posted July 15, 2011 you want set the ped rotation? setElementPosition Link to comment
qaisjp Posted July 15, 2011 Author Share Posted July 15, 2011 No offense, but I'm not that stupid. I want to set the ped rotation to where the camera is facing. Also, setElementPosition for ped rotation? pfft, i would use setPedRotation Link to comment
Wojak Posted July 15, 2011 Share Posted July 15, 2011 https://wiki.multitheftauto.com/wiki/GetCameraMatrix https://wiki.multitheftauto.com/wiki/FindRotation Link to comment
JR10 Posted July 15, 2011 Share Posted July 15, 2011 Something like this: -- CLIENT SIDE local sX, sY = guiGetScreenSize() local x, y, z = getWorldFromScreenPosition(sX/2, sY/2, 10) local px, py = getElementPosition(getLocalPlayer()) setPedRotation(getLocalPlayer(), findRotation(px, py, x, y)) 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 Link to comment
qaisjp Posted July 15, 2011 Author Share Posted July 15, 2011 To all the people who gave me things to use, no thanks. Thanks a lot JR for giving me what I needed, i will test now. Hm..doesnt work Link to comment
JR10 Posted July 15, 2011 Share Posted July 15, 2011 Try this: -- CLIENT SIDE local sX, sY = guiGetScreenSize() local locplayer = getLocalPlayer() addEventHandler("onClientPreRender", root, function() local x, y, z = getWorldFromScreenPosition(sX/2, sY/2, 10) local px, py = getElementPosition(locplayer) setPedRotation(locplayer, findRotation(px, py, x, y)) 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 Link to comment
qaisjp Posted July 15, 2011 Author Share Posted July 15, 2011 ^^ JR10, I already tried this, it bugs up a bit. Link to comment
JR10 Posted July 15, 2011 Share Posted July 15, 2011 Hmm, -- CLIENT SIDE local sX, sY = guiGetScreenSize() local locplayer = getLocalPlayer() addEventHandler("onClientPreRender", root, function() local x, y, z = getWorldFromScreenPosition(sX/2, sY/2, 10) local px, py, pz = getElementPosition(locplayer) setElementRotation(locplayer, 0, 0, findRotation(px, py, x, y)) 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 Link to comment
Wojak Posted July 15, 2011 Share Posted July 15, 2011 try to replace this: local x, y, z = getWorldFromScreenPosition(sX/2, sY/2, 10) local px, py, pz = getElementPosition(locplayer) setElementRotation(locplayer, 0, 0, findRotation(px, py, x, y)) with this: local x,y,z,px,py = getCameraMatrix() setPedRotation(locplayer, findRotation(px, py, x, y)) To all the people who gave me things to use, no thanks. I can't belive that people are this lazy this days... edit: lol, actually i was wrong but this works fine: local sX, sY = guiGetScreenSize() local locplayer = getLocalPlayer() addEventHandler("onClientPreRender", root, function() local x, y, z = getWorldFromScreenPosition(sX/2, sY/2, 10) local px, py, pz = getElementPosition(locplayer) setElementRotation(locplayer, 0, 0,360- findRotation(px, py, x, y)) 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 edit2 version wit camera matrix: local x,y,z,px,py = getCameraMatrix() setElementRotation(locplayer, 0, 0,180-findRotation(px, py, x, y)) Link to comment
JR10 Posted July 15, 2011 Share Posted July 15, 2011 You are right, i forgot the 360. Link to comment
qaisjp Posted July 15, 2011 Author Share Posted July 15, 2011 I'm not being lazy, it's just that I find it hard to concentrate on one small bug when there is so many other things to do before I fix it, but I assumed there was numerous calculations, that is why I asked I'm trying now. EDIT: The screen size one didn't work as good as the camera matrix one did, but I think there is a conflit in the code I have that makes me go the opposite way. Link to comment
[DemoN] Posted July 17, 2011 Share Posted July 17, 2011 x,y,z,tx,ty,tz = getCameraMatrix() myAngle = (( 360 - math.deg ( math.atan2 ( ( x - tx ), ( y - ty ) ) ) ) % 360)-180 setPedRotation( getLocalPlayer(), myAngle ) not tested... Link to comment
qaisjp Posted July 18, 2011 Author Share Posted July 18, 2011 Well thanks DemoN, once i get my friend to get back from his 4 hour walk and restart the server (trololo i crashed my server just by typing /refresh) i will test it 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