Physics [UE4]: Implement a “maximum compression” for vehicle-suspension
Hey BoredEngineer, thanks for for answer. I am not sure if I understood that to 100% but I will try to implement it today and test a bit around, to see if I get the idea of the approach :)
Thanks!
I don't get this point:
- Increasing the suspension travel.
- Using stiffer springs. Even increasing the spring rate in runtime would be better than applying a force externally.
- Raising the bottom of the vehicle's collider. It's not necessary that the collider encloses the entire visual mesh.
What I mean is simulating collision manually. Take a look at code snippets here, just ignore friction part:Hey BoredEngineer, thanks for for answer. I am not sure if I understood that to 100% but I will try to implement it today and test a bit around, to see if I get the idea of the approach :)
Thanks!
http://www.gamedev.net/topic/465248-calculating-impulse-due-to-rigid-body-collision-with-friction/
It was a naming error in my pseudo-code, sorry. It should have been named DownVelocityMagnitude.
@BoredEngineer
Sure, my approach is the following:
float WheelTraceHitDistance = LineTraceResult.HitDistance;
float SuspensionForce; //Basic Suspension Spring Force Constant;
float SuspensionSize; //Trace Length & overall size of the suspension
float SuspensionDampingConstant;
In principal you can make springs so stiff that they will work as almost solid rods.
This is a correct theory, but in practice PhysX (the underlying physics engine in UE) doesn't handle these cases very good. Too much stiff springs and/or large damper values can incur in numeric instabilities giving the a vehicle a "jittery" behavior even at rest.
In principal you can make springs so stiff that they will work as almost solid rods.
This is a correct theory, but in practice PhysX (the underlying physics engine in UE) doesn't handle these cases very good. Too much stiff springs and/or large damper values can incur in numeric instabilities giving the a vehicle a "jittery" behavior even at rest.
It's not to do with PhysX(or any other engine), but with frequency. At the low frequency at high stiffness and, e.g. 1 cm compression if it applies 15000 force, the car of weight 10000 N(~1020 kg) will receive 1.5 G acceleration. If the frequency is 60 Hz, than it will be
9.8 * 1.5 * (1/60) = 0.245
. If it moves 0.245 m in one frame, it becomes flying. And dampers won't solve it much in this case. However, once we change it to, let's say, 300 Hz:
9.8 * 1.5 * (1/300) = 0.049
. It's 5 cm only. In this specific case(of so stiff springs) it would still make it bounce a bit(actually 3.9 cm is quite a lot. It would be a bit smaller, though, due to dampers), but it would be way less noticeable. At this frequency our eyes would also not notice it. However, most of nowadays computers yet can't handle such a crazy frequencies.
A "solution" might be using another springs at the top part. Once the spring compresses enaugh, a thing joined to the wheel's joint starts to compress the second spring. This spring adds huge additional force pushing tire downwards. The reaction of this pushes car upwards. This spring could use semi-conical shape(and result in non-linear, rather exponentional or similar force basing on compression). I don't know if this is realistic, though. I learnt this method from Racer documentation.
You may also consider that the spring force of the springs may be non-linear depending on spring proprties.
It's not to do with PhysX(or any other engine), but with frequency.
In this case that issue has to do with the implementation in PhysX 3.x. I don't know about other engines.
In previous version (PhysX 2.x) the wheel component was part of the physics core, so it handled stiff spring perfectly. You could even set ridiculously large spring rate values and the suspension would keep perfectly stable, behaving mostly as a hard contact rather than a spring, no matter the actual frequency of the simulation.
This doesn't happen in PhysX 3.x. Here the vehicle code was extracted out of the core physics into a kind of "add-on" module. This module combines a faulty vehicle model with a terrible implementation. One of the consequences is the suspension becoming unstable and/or physically incorrect unless the parameters are combined so they match very specific conditions. Even when those conditions are matched, the suspension exhibits instabilities at some ranges (i.e. large spring rates) due to the faulty implementation.