Tinker with physics a bit

This commit is contained in:
Miloslav Ciz 2025-04-28 16:06:36 +02:00
parent 71a034d74c
commit 9dfbeae0d4
3 changed files with 29 additions and 17 deletions

View file

@ -1475,7 +1475,22 @@ uint32_t LCR_racingStep(unsigned int input)
{
TPE_Joint tmpJoint = LCR_racing.carBody.joints[i];
LCR_racing.carBody.joints[i] = joints[i];
joints[i] = tmpJoint;
if (LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED)
{
// if unsuccessful, keep the original pre-step pos. and decrease speed
joints[i].velocity[0] /= 2;
joints[i].velocity[1] /= 2;
joints[i].velocity[2] /= 2;
}
else
{
// in normal case back up this step and revert the body total lin. vel.
joints[i] = tmpJoint;
joints[i].velocity[0] /= LCR_CAR_JOINTS;
joints[i].velocity[1] /= LCR_CAR_JOINTS;
joints[i].velocity[2] /= LCR_CAR_JOINTS;
}
}
LCR_racing.carBody.flags &= ~TPE_BODY_FLAG_NONROTATING;
@ -1487,19 +1502,8 @@ uint32_t LCR_racingStep(unsigned int input)
{
LCR_LOG2("using simplified physics");
for (int i = 0; i < LCR_CAR_JOINTS; ++i) // use the first step positions
for (int i = 0; i < LCR_CAR_JOINTS; ++i) // use the first step result
LCR_racing.carBody.joints[i] = joints[i];
// If still not OK (slim chance), just stop the body (prevent uberbugs):
if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) ||
!_LCR_racingCarShapeOK())
{
TPE_bodyStop(&LCR_racing.carBody);
for (int k = 0; k < 2 * TPE_RESHAPE_ITERATIONS; ++k)
TPE_bodyReshape(&LCR_racing.carBody,_LCR_racingEnvironmentFunction);
}
}
}