From 72b28f2bb079eeb3098ca3f1786c655ec23c692b Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Mon, 3 Mar 2025 17:02:41 +0100 Subject: [PATCH] Fix car sliding --- TODO.txt | 1 + racing.h | 10 ++++++---- tinyphysicsengine.h | 7 ++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/TODO.txt b/TODO.txt index 4e6a915..cf34c0d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,6 @@ =========== GENERAL ============== +- car deglitch idea: deglitch only if the middle joint collided this frame? - some kinda easteregg in menu or smt - make the U-ramp map taller due to new physics - replay format should probably record game version diff --git a/racing.h b/racing.h index a1c8ea7..9eab5ed 100644 --- a/racing.h +++ b/racing.h @@ -1156,11 +1156,13 @@ uint32_t LCR_racingStep(unsigned int input) LCR_racing.carBody.joints[4].velocity[1], LCR_racing.carBody.joints[4].velocity[2]); - // apply gravity only if wheels are on the ground (prevents sliding a bit): + /* Apply gravity like this: if all wheels are on ground, we don't apply + gravity to roof. This helps prevent sliding. */ - if (((LCR_racing.wheelCollisions | (LCR_racing.wheelCollisions >> 4)) - & 0x0f) != 0x0f) - TPE_bodyApplyGravity(&(LCR_racing.carBody),LCR_GRAVITY); + for (i = 0; i < 5; ++i) + if (i < 4 || (((LCR_racing.wheelCollisions | + (LCR_racing.wheelCollisions >> 4)) & 0x0f) != 0x0f)) + LCR_racing.carBody.joints[i].velocity[1] -= LCR_GRAVITY; if (LCR_racing.wheelCollisions) // at least one wheel on ground? { diff --git a/tinyphysicsengine.h b/tinyphysicsengine.h index e48ec74..737392b 100644 --- a/tinyphysicsengine.h +++ b/tinyphysicsengine.h @@ -2,6 +2,9 @@ #define _TINYPHYSICSENGINE_H /** + NOTE: This is a Licar specific fork of the library. Changes made can be + found e.g. with diff. + tinyphysicsengine (TPE) Simple/suckless header-only hybrid 3D physics engine with no floating point, @@ -1038,7 +1041,9 @@ void TPE_worldStep(TPE_World *world) if (hard) { - TPE_bodyReshape(body,world->environmentFunction); + /* Licar modification: we only reshape if the tension requires it. This + prevents car from sliding when standing on ground. */ + // TPE_bodyReshape(body,world->environmentFunction); bodyTension /= body->connectionCount;