Jump to content

Calculating coordinates behind a vehicle.


Recommended Posts

As the title said, how to calculate the world coordinates of the behind of vehicle?

Like this: 980de82666.png

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? :D

Link to comment
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 

To get the co-ordinates behind the vehicle, simply do something like this;

local vX, vY, vZ = getPositionFromElementOffset(0, -1, 0) 

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