Jump to content

Function of getPosition 1 meter in front of ped, cant fint


Recommended Posts

Hey guys, I would be really nice if there was some function like this.. so I dont need to put manual markers on my map files.

Is it possible to get the position 1 meter in front of any ped?

I mean I want to place a marker in front of a ped.. not on his back!! in front, like u were buying something from him.

Is there any function to get the position of that spot?

Thanks!

Link to comment

Proceed to

getElementMatrix() 

There is fine examples of what you need. Only for peds and vehicles.

And if in case you need to do it serverside

function getPositionInFront(element,meters) 
   local x, y, z = getElementPosition ( element ) 
   local a,b,r = getVehicleRotation ( element ) 
   x = x - math.sin ( math.rad(r) ) * meters 
   y = y + math.cos ( math.rad(r) ) * meters 
   return x,y,z 
end 

Link to comment
Proceed to
getElementMatrix() 

There is fine examples of what you need. Only for peds and vehicles.

And if in case you need to do it serverside

function getPositionInFront(element,meters) 
   local x, y, z = getElementPosition ( element ) 
   local a,b,r = getVehicleRotation ( element ) 
   x = x - math.sin ( math.rad(r) ) * meters 
   y = y + math.cos ( math.rad(r) ) * meters 
   return x,y,z 
end 

Hmm I understand I need some math calculations, and use Pythagorean theorem :)

Didnt know about that, I will try that later, first need to fix the rotation problem.

Thanks for your help mate!

Link to comment
Yes, but bare in mind that if a coordinate is negative it will get inversed

Hmm what do u mean? if an X is negative it will become positive?

Btw I dont get it why you use subtraction on Y and addition on X. In my head would be addition for both :S but I might be wrong.

Can you explain me? thanks.

I understand this part " math.sin ( math.rad® ) * meters " you dont need to explain :)

Thanks in advance!!

Link to comment
Just take it into account that coord values can be negative ^^

Try to subtract both values, so from the result you'll imagine easier how its working.

Yees! I found out why the substraction on Y!! Because we need to use sin there, and sin is negative between 180 degrees and 360 degrees, right ? :)

Thanks buffalo!

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