d0p3t
4
The best way to do this is take two vectors (1. world coordinate 2. vehicle position coordinate) and find the Euclidean distance.
In C# this would look like:
Vector3 worldCoordinate = new Vector3(0,0,0);
Vector3 vehiclePosition = Game.PlayerPed.CurrentVehicle.Position;
float distance = worldCoordinate.DistanceSquared(vehiclePosition);
then you can use this distance as the radius.
if(distance < 3f)
{
// do something
}
In Lua, I’m not sure. I know that there are natives like Vdist2() and GetDistanceBetweenCoords() but doing it without a native is faster. Something like:
if (Vdist2(posX, posY, posZ, carX, carY, carZ) < 3) then
-- do something
end
but faster (from the natives documentation Native Reference - Cfx.re Docs)
dist = #(vector3(0.0, 0.0, 0.0) - vector3(5.0, 5.0, 5.0))
2 Likes