MTA Team qaisjp Posted July 15, 2011 MTA Team 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?
#Paper Posted July 15, 2011 Posted July 15, 2011 you want set the ped rotation? setElementPosition My skype: skiper964 I helped you? Help me! ^^ Help me bro! ^^
MTA Team qaisjp Posted July 15, 2011 Author MTA Team 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
Wojak Posted July 15, 2011 Posted July 15, 2011 https://wiki.multitheftauto.com/wiki/GetCameraMatrix https://wiki.multitheftauto.com/wiki/FindRotation create your teleports and interiors in MTA map editor want more excitment in your race map? - add a killer bot you may also add some peds (NPC) - CARMAGEDDON STYLE! 2paq MTA:SA Race Server
JR10 Posted July 15, 2011 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 Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
MTA Team qaisjp Posted July 15, 2011 Author MTA Team 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
JR10 Posted July 15, 2011 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 Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
MTA Team qaisjp Posted July 15, 2011 Author MTA Team Posted July 15, 2011 ^^ JR10, I already tried this, it bugs up a bit.
JR10 Posted July 15, 2011 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 Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Wojak Posted July 15, 2011 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)) create your teleports and interiors in MTA map editor want more excitment in your race map? - add a killer bot you may also add some peds (NPC) - CARMAGEDDON STYLE! 2paq MTA:SA Race Server
JR10 Posted July 15, 2011 Posted July 15, 2011 You are right, i forgot the 360. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
MTA Team qaisjp Posted July 15, 2011 Author MTA Team 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.
[DemoN] Posted July 17, 2011 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... My in game nick is Lemonade
MTA Team qaisjp Posted July 18, 2011 Author MTA Team 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
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