Fiddle with physics again

This commit is contained in:
Miloslav Ciz 2025-05-03 18:02:32 +02:00
parent a9c8bd1c4b
commit 68df5326d7
2 changed files with 37 additions and 8 deletions

View file

@ -2,6 +2,7 @@ fuck issue trackers :D
=========== GENERAL ==============
- LOD blocks in lower res look too small
- hitting ramps at higher speed still often bugs, try to fiddle with physics
again (reshape iterations, tension, ...)
- make replays have better names (time etc.)

View file

@ -62,11 +62,15 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_PHYSICS_UNIT 4096 ///< len. of square for phys. engine
#define TPE_RESHAPE_TENSION_LIMIT 8
#define TPE_RESHAPE_ITERATIONS 16 /**< Empirically tested, seems to have a
big impact on bugs that happen when
driving onto a curved ramp under
various angles. */
/* The combination of values TPE_RESHAPE_TENSION_LIMIT and
TPE_RESHAPE_ITERATIONS has crucial effect on the bugginess and feel of car
physics, especially when driving onto ramps in high speed etc., the values
were chosen empirically by testing, these are the ones that showed to
subjectively feel the best. */
#define TPE_RESHAPE_TENSION_LIMIT 7
#define TPE_RESHAPE_ITERATIONS 18
#include "general.h"
#include "map.h"
#include "tinyphysicsengine.h"
@ -1504,8 +1508,31 @@ uint32_t LCR_racingStep(unsigned int input)
TPE_worldStep(&(LCR_racing.physicsWorld)); // normal step
if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) ||
!_LCR_racingCarShapeOK()) // bad?
uint8_t useSimplified = (LCR_racing.carBody.flags &
TPE_BODY_FLAG_UNRESOLVED) != 0;
if (!useSimplified && !_LCR_racingCarShapeOK())
{
useSimplified = 1;
// we only do this with wheels on ground, because squeezed roof bugs here
if ((LCR_racing.wheelCollisions & 0x0f) == 0x0f)
for (int i = 0; i < 4 * TPE_RESHAPE_ITERATIONS; ++i)
{
LCR_LOG2("trying harder to resolve physics");
TPE_bodyReshape(&LCR_racing.carBody,_LCR_racingEnvironmentFunction);
if ((i % 4 == 0) && _LCR_racingCarShapeOK())
{
LCR_LOG2("succeeded in fixing physics");
useSimplified = 0;
break;
}
}
}
if (useSimplified)
{
LCR_LOG2("using simplified physics");
@ -1555,6 +1582,7 @@ uint32_t LCR_racingStep(unsigned int input)
}
// Accelerate roof and wheels away from each other:
for (int i = 0; i < LCR_CAR_JOINTS; ++i)
{
LCR_racing.carBody.joints[i].velocity[0] += (i == 4 ? 1 : -1) * tmpVec.x;