Jump to content

[SNIPPET][CLIENT]GetXYInFrontOfPlayer


Hell_Demon

Recommended Posts

function getXYInFrontOfPlayer( distance ) 
    local x,y,z = getElementPosition( getLocalPlayer() ) 
    local rotation = getPlayerRotation( getLocalPlayer() ) 
    rotation = rotation/180*3.141592 
    x = x + ( math.sin(rotation) * distance ) 
    y = y + ( math.cos(rotation) * distance ) 
    return x, y 
end 

I didn't test this because I dont have MTA installed at the moment, its a conversion from GetXYInFrontOfPlayer on sa-mp.

If there are problems post them here :)

Edited by Guest
Link to comment

A few things:

+ return x,y (already pointed out)

+ It's probably x = x - math.sin(...) (not x = x + )

+ rotation as returned from getPlayerRotation() is in degrees. math.sin/cos are in radians so you'll need math.rad() in there.

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