Getting the vehicle behind you

So i’m working on a few scripts, and could easily get vehicles located in front of me with CastRayPointToPoint, but how do I now flip this to get the vehicle located behind me?

I’m using this function I found around the forums, but am a tad bit confused. Thanks in advance for any help supplied.

function getVehicleInDirection(coordFrom, coordTo)
	local rayHandle = CastRayPointToPoint(coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, GetPlayerPed(-1), 0)
	local a, b, c, d, vehicle = GetRaycastResult(rayHandle)
	return vehicle
end

You can do

local backwardPosition = GetOffsetFromEntityInWorldCoords( vehicle, 0, -30.0, 0 )

to get the coords of 30 units behind the player, then you’d use the getVehicleInDirection function to draw a raycast behind the player.

2 Likes