# Calculating coordinates behind a vehicle.

## Recommended Posts

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 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? If it's client-side you can calculate it using getElementMatrix, there's an example on wiki that's exactly what you need.

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 + offY * m + offZ * m + m  -- Apply transform
local y = offX * m + offY * m + offZ * m + m
local z = offX * m + offY * m + offZ * m + m
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)
```

## Create an account

Register a new account