Jump to content

Somewhere on this forum the script is there...


qaisjp

Recommended Posts

  • MTA Team
Posted

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?

  • MTA Team
Posted

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

Posted

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 

  • MTA Team
Posted

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 :S

Posted

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 

Posted

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 

Posted

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

  • MTA Team
Posted

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

Posted
x,y,z,tx,ty,tz =  getCameraMatrix() 
myAngle = (( 360 - math.deg ( math.atan2 ( ( x - tx ), ( y - ty ) ) ) ) % 360)-180 
        setPedRotation( getLocalPlayer(), myAngle ) 

not tested...

  • MTA Team
Posted

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

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