Fix physics even more

This commit is contained in:
Miloslav Ciz 2025-04-23 17:11:47 +02:00
parent 0e694589eb
commit c22f17ef8c
3 changed files with 22 additions and 12 deletions

View file

@ -1450,14 +1450,22 @@ uint32_t LCR_racingStep(unsigned int input)
TPE_Joint joints[LCR_CAR_JOINTS];
if (!_LCR_racingCarShapeOK())
printf("NOT OOOOOOOOOOOK\n");
TPE_Vec3 linearVel = TPE_bodyGetLinearVelocity(&LCR_racing.carBody);
/* Now back up the joints and also set all current joint velocities to the
average linear velocity (since non-rotating bodies only consider the
first joint's velocity, it must be the average of the whole body, else
the car is super fast): */
for (int i = 0; i < LCR_CAR_JOINTS; ++i)
{
joints[i] = LCR_racing.carBody.joints[i];
LCR_racing.carBody.joints[i].velocity[0] = linearVel.x;
LCR_racing.carBody.joints[i].velocity[1] = linearVel.y;
LCR_racing.carBody.joints[i].velocity[2] = linearVel.z;
}
LCR_racing.carBody.flags |= TPE_BODY_FLAG_NONROTATING;
for (int i = 0; i < LCR_CAR_JOINTS; ++i)
joints[i] = LCR_racing.carBody.joints[i];
TPE_worldStep(&(LCR_racing.physicsWorld)); // non-rotating step
for (int i = 0; i < LCR_CAR_JOINTS; ++i) // remember the position and reset
@ -1484,14 +1492,11 @@ if (!_LCR_racingCarShapeOK())
if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) ||
!_LCR_racingCarShapeOK())
{
printf("SASASASSASASASASASASSAS\n");
TPE_bodyStop(&LCR_racing.carBody);
for (int k = 0; k < 2 * TPE_RESHAPE_ITERATIONS; ++k)
TPE_bodyReshape(&LCR_racing.carBody,_LCR_racingEnvironmentFunction);
for (int k = 0; k < 2 * TPE_RESHAPE_ITERATIONS; ++k)
TPE_bodyReshape(&LCR_racing.carBody,_LCR_racingEnvironmentFunction);
}
}
}