Jump to content

Somewhere on this forum the script is there...


qaisjp

Recommended Posts

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

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

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

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

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.

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