Hell_Demon Posted April 28, 2008 Share Posted April 28, 2008 (edited) 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 April 28, 2008 by Guest Link to comment
lil Toady Posted April 28, 2008 Share Posted April 28, 2008 return x, y instead of return x return y It exits the function as soon as 'return' is fired in any programming/scripting language i know, so in your case it'd only return x Link to comment
tma Posted April 28, 2008 Share Posted April 28, 2008 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
Hell_Demon Posted April 28, 2008 Author Share Posted April 28, 2008 I thought the multiple returns in lua meant more then 1 return after eachoter meh didnt know it needed to be on 1 line Link to comment
Cazomino05 Posted April 28, 2008 Share Posted April 28, 2008 theres a pi function the the math librarys too its a bit more acurate Link to comment
DiSaMe Posted April 28, 2008 Share Posted April 28, 2008 theres a pi function the the math librarys too its a bit more acurate And it's best to use math.rad() instead of rotation = rotation/180*3.141592 Link to comment
Hell_Demon Posted April 29, 2008 Author Share Posted April 29, 2008 i dont think people will go 'omg i will never join this server again! the car/player spawned 0.00001 cm to far to the right' 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