We’ve put together a custom street racing resource and I’m finding that if I use really big checkpoints, like as wide as the entire bridge just south of FOrt Zancudo, there seems to be issues detecting that a player has driven through it. Seems you need to go straight down the middle, but then there are other smaller ones we’ve placed, some detect near the edges others not. Is there a knwon maximum width you should make them, or is there another way to do it all manually not using the native?
Can you show us a snippet of the code where you render the checkpoints and calculate if a player passed it? Maybe there is an error in there.
Ok, so this was put together by a new guy we’re bringing into our team. I found the distance detection codea dn having been playing with it. This video shows how far off the calculations are FiveM Distance issue with checkpoints - YouTube
The markers have a radius of 7.0 but you can see in the top right the distance calculated to the centre of the marker. The ped is nowhere near the circle yet the distance reported of 7 should be when the ped is at the edge of the circle with the bonnet of the car inside the circle.
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if(inRace) then
local pedPos = GetEntityCoords(PlayerPedId())
local nextCheckpoint = currentCheckpoint+1
--if(#(vector3(currentRace.checkpoints[nextCheckpoint].pos.x, currentRace.checkpoints[nextCheckpoint].pos.y, currentRace.checkpoints[nextCheckpoint].pos.z) - pedPos) < currentRace.checkpoints[nextCheckpoint].r) then
local distance = GetDistanceBetweenCoords(
currentRace.checkpoints[nextCheckpoint].pos.x,
currentRace.checkpoints[nextCheckpoint].pos.y,
currentRace.checkpoints[nextCheckpoint].pos.z,
pedPos.x,
pedPos.y,
pedPos.z,
false)
DrawMessage(distance)
if(distance < currentRace.checkpoints[nextCheckpoint].r) then
print('distance to centre')
print(distance)
DeleteCheckpoint(currentRace.checkpoints[nextCheckpoint].checkpoint)
RemoveBlip(currentRace.checkpoints[nextCheckpoint].blip)
currentCheckpoint = currentCheckpoint + 1
PlaySound(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0, 0, 1)
nextCheckpoint = currentCheckpoint+1
if(currentRace.checkpoints[nextCheckpoint] ~= nil) then
local nextCheckPos = currentRace.checkpoints[nextCheckpoint].pos
local nextCheckRadius = currentRace.checkpoints[nextCheckpoint].r
currentRace.checkpoints[nextCheckpoint].blip = AddBlipForCoord(nextCheckPos.x, nextCheckPos.y, nextCheckPos.z)
AddTextEntry("CP" .. nextCheckpoint, 'Checkpoint #' .. nextCheckpoint)
BeginTextCommandSetBlipName("CP" .. nextCheckpoint)
EndTextCommandSetBlipName(currentRace.checkpoints[nextCheckpoint].blip)
if(currentRace.checkpoints[nextCheckpoint+1] ~= nil) then
currentRace.checkpoints[nextCheckpoint].checkpoint = CreateCheckpoint(1, nextCheckPos.x, nextCheckPos.y, nextCheckPos.z, currentRace.checkpoints[nextCheckpoint+1].pos.x, currentRace.checkpoints[nextCheckpoint+1].pos.y, currentRace.checkpoints[nextCheckpoint+1].pos.z, nextCheckRadius, 222, 174, 62, 150, 0)
else
currentRace.checkpoints[nextCheckpoint].checkpoint = CreateCheckpoint(4, nextCheckPos.x, nextCheckPos.y, nextCheckPos.z, 0.0, 0.0, 0.0, nextCheckRadius, 222, 174, 62, 150, 0)
end
else
I must be missing something simple, just not sure exactly what.
Okay, so from my knowledge ist that in the distance check you need to have the diameter of the checkpoint not the radius so if i create a Checkpoint with 25.0 as radius
CreateCheckpoint(4, checkpoints[id + 1], checkpoints[id + 1], 25.0, 255, 234, 146, 150, 0)
the check must be with 12.5 than it works in my code without any problems
if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1), true) , checkpoints[current_active_checkpoint_id]) < 12.5 and has_finished == false then
Ah fair enough. I’ll multiply by 2 then for the size of the marker, or divide the distance check / 2. Didn’t look like double though, but must be.
Yeah it is not so obvious in the documentation, but i tried some things in the past and found out that it worked like this