From f959b3477b0456ae734983e395d76fac5dcd0bbc Mon Sep 17 00:00:00 2001 From: genkaok Date: Fri, 27 Aug 2021 19:27:04 +0300 Subject: [PATCH] Add ABS function When braking, we check every 50 milliseconds whether the wheel is locked and if it is locked, we turn off the brake --- src/vehicles/Vehicle.cpp | 10 ++++++++++ src/vehicles/Vehicle.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index d1054191..fc7a4357 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -860,6 +860,16 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon #endif } } + else { + if(pHandling->bABS && brake != 0.0f && brake < 1.0f && brake > adhesion) { + if((uint16)m_fBrakeABSTimer[wheelId] < CTimer::GetTimeStepInMilliseconds()) { + m_fBrakeABSTimer[wheelId] = 50; + brake = adhesion; + } else { + m_fBrakeABSTimer[wheelId] -= CTimer::GetTimeStepInMilliseconds(); + } + } + } if(brake > adhesion){ if(Abs(contactSpeedFwd) > 0.005f) diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h index b59b6b19..dd45afeb 100644 --- a/src/vehicles/Vehicle.h +++ b/src/vehicles/Vehicle.h @@ -277,6 +277,7 @@ public: CStoredCollPoly m_aCollPolys[2]; // poly which is under front/rear part of car float m_fSteerInput; eVehicleType m_vehType; + float m_fBrakeABSTimer[4]; static void *operator new(size_t) throw(); static void *operator new(size_t sz, int slot) throw(); -- 2.45.2