fix infinite drift

This commit is contained in:
fnicon 2026-03-21 12:01:06 +09:00
parent 391010b4c4
commit 29c701ce6a
2 changed files with 18 additions and 3 deletions

View File

@ -31,8 +31,8 @@ function wrapper:load(_args)
{
assemblage = racer.assemble,
data = {
accel = 20.0,
brake = 10.0,
accel = 200.0,
brake = 100.0,
grip = 1.0,
max_speed = 50.0,
steer = 5.0,

View File

@ -238,7 +238,8 @@ local magic_n = {
scale_y = 1000.0,
centrifugal_r = 1.0,
magic_slowdown = 10.0,
magic_boost = 1000.0
magic_boost = 10000.0,
magic_slow_drift = 10.0
}
function system:update(dt)
@ -285,6 +286,20 @@ function system:update(dt)
local centrifugal = racing_phy.centrifugal_force(dt, mass, new_velocity * magic_n.centrifugal_r, max_speed)
f_lateral = add_centrifugal(f_lateral, centrifugal)
if (not left and not right) then
if (not (left) and f_lateral > 0) then
f_lateral = f_lateral - (magic_n.magic_slow_drift)
if (f_lateral < 0) then
f_lateral = 0
end
elseif (not right and f_lateral < 0) then
f_lateral = f_lateral + (magic_n.magic_slow_drift)
if (f_lateral > 0) then
f_lateral = 0
end
end
end
e[race.dict.inertia].data = {f_forward * dt, f_lateral * dt}
local new_angle = e["race.angle"].data + f_lateral * dt/mass