roaddog Posted February 20, 2015 Posted February 20, 2015 As the title said, how to calculate the world coordinates of the behind of vehicle? Like this: I tried the getVehicleComponentPosition but getting confused because of this vehicle component
jingzhi Posted February 20, 2015 Posted February 20, 2015 As the title said, how to calculate the world coordinates of the behind of vehicle?Like this: I tried the getVehicleComponentPosition but getting confused because of this vehicle component You can use getElementPosition and getElementRotation, e.g. if you are facing north then -5 in the y of your current position, if you facing south then +5, but you need to find out the trigonometry formula determine how much you add or subtract on the y or x axis. Btw why you need this?
MIKI785 Posted February 20, 2015 Posted February 20, 2015 If it's client-side you can calculate it using getElementMatrix, there's an example on wiki that's exactly what you need.
Dealman Posted February 20, 2015 Posted February 20, 2015 If it's client-side you can calculate it using getElementMatrix, there's an example on wiki that's exactly what you need. More specifically, you'll want to use this example; function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end To get the co-ordinates behind the vehicle, simply do something like this; local vX, vY, vZ = getPositionFromElementOffset(0, -1, 0)
roaddog Posted February 20, 2015 Author Posted February 20, 2015 Ah, after reading over and over again, I have understood now. Thanks for helping me out.
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