Vehicle physics C++/Vulkan

Опубликовано: 11 Декабрь 2023
на канале: Lewa
1,118
56

Revisited my attempt at creating a raycast based vehicle physics model from a while back and actually managed to fix some of the longer standing issues.
For one i found out that my physics abstraction layer (for PhysX) was applying the force vectors incorrectly (which lead to incorrect tire behaviour). The other two things were an incorrectly implemented feedback loop between the engine, drivetrain and wheels and at last the issue with the pacejka tire model at low speeds (which often leads to jittery wheels due to floating point inaccuracies.)

For those interested how i solved the pacejka low speed issue:
First you have to make sure that you get your feedback loop right.
The engine is connected to the drivetrain which is in turn connected to the wheels. The engine applies a force through the drivetrain (torque) which is applied on the wheels. The wheels spin, cause friction (an opposing torque) which is then fed back to the drivetrain and engine. If you get the parameters right (the wheels and drivetrain have inertia as they also have a mass) you will notice that they will already (at least slightly) dampen the oscillation from the pacejka tire model.

However this was not enough.
My solution to the jitter issue on the tires is to calculate the angular velocity of the current frame from the tire (due to the tire friction rotating this wheel) and then predict how the wheel would behave one frame in the future (by advancing your engine/drivetrain wheel simulation again in the same update cycle). You than check if the wheels angular velocity would change.
If you are at a lower speed (for example under 5 km/h) and the prediction determines that the wheels angular velocity would change directions then you can assume that you suffer from tire jittering. (You basically detect oscillations in your tire model.)
If that's the case, i switch the tires to a "sticky" mode which makes the tires adjust its angular velocity to the ground velocity. (It's an oversimplification as i do other stuff with the tire model to handle edge cases but that's the gist of it.) You remain in the "sticky" state as long as your prediction says that the tire oscillates. If you for example accellerate with full throttle (sending max power through the wheels) the tire would spin so fast that the friction force would not be able to reverse the wheels angular velocity (thus the prediction code would find that the tire would not oscillate anymore and exit the sticky state.)

It's a unique solution to a problem that i haven't seen anywhere on the internet from all my research that i have conducted. This is the first solution that somehow works. (Although i haven't tested it yet properly so there might be some edge cases were issues will still arise.)

For now i'm happy with the solution and i'm confident that the current implementation is sufficient enough as a foundation for racing/vehicle based games.

Will have more updates soon.