Skip to content

Small pieces

Ilja Jusupov edited this page Oct 11, 2024 · 1 revision

I’m going to add some helpful bits of Lua code here for future use.

Check if car is still on valid track surface

local function isOnValidTrack()
  local car = ac.getCar(0)
  local invalid = 0
  for i = 0, 3 do
    if car.wheels[i].surfaceValidTrack then
      invalid = invalid + 1
    end
  end
  return invalid < 2  -- returns true if 1 wheel is off track, but false if 2 or more are outside
end

For New Modes or Online Scripts using physics API, you might also want to add this line to hide original lap invalidation message:

setInterval(function ac.markLapAsSpoiled(true) end, 0)

It will mark lap as spoiled hiding that message every frame, to ensure it’ll never be shown.

(A bit of an explanation for all this mess: there are some entities keeping track of lap times, such as Assetto Corsa itself, Content Manager, or, for example, other apps such as Sidekick, and since they have no clue about physics API, their databases can get seriously messed up registering laps in which cars were teleported around or, let’s say, had extra force pushing them forward. That’s why any usage of physics API invalidates lap times: thankfully, most of them respect that flag and will discard the lap time. If you want to teleport car around while counting time, the best solution might be to count time manually, similar to how Rally mode is doing it. And if done properly, you could actually achieve sub-3 ms accuracy too: just keep distance to finishing line and precise time from frame before crossing the line, so you could interpolate and find the exact time of the line crossing.)

Clone this wiki locally