I’m having a really strange behaviour occur with my objects’ physics. I’m attempting to set the rotational velocity of my object, but only on two of it’s local axes, to make it self-right depending on it’s rotation relative to a given normal.
This is much easier to describe with a video, so here it is:
Notice the odd behaviour, if the craft is facing either the positive-X or negative-X direction, the craft behaves as it should, righting itself to follow the normal of the terrain below it. However, as soon as the craft starts facing more towards Positive-Y or Negative-Y, it starts getting madly out of control, until it starts to face positive/negative-X again and returns to the proper behaviour. For some reason as it starts to line up with the Y-axis, it starts going mental. I’ve posted the psuedo-logic below and the video does the same thing in Blueprint.
I’ve done the same logic for the craft in both C++ and in Blueprints, and experienced the same behaviour with both. I’ve tried rotating the Normal and the ‘Alpha’ force around various rotations and still had no luck. I’m convinced it must be something wrong with the way the logic is being conducted, but can’t for the life of me figure out what it is, and I’m following the logic of another game that works perfectly with this technique (according to reliable sources). Can anybody highlight where I’m going wrong?
I have also tried using Physics Forces (AddTorque), but that yields the same problem, and later down the line will be harder to replicate anyway, so ideally I want to set the rotational velocity directly.
Omega = Angular Velocity (Local-Space) Alpha = Angular Acceleration Normal = World-Space Normal of Terrain Beneath Vehicle (From Line Trace) Alpha Damp = Damping Value. Alpha Track = Speed at which it tries to right itself. Pitch and roll damping: alpha.x = -alphaDamp * omega.x alpha.y = -alphaDamp * omega.y Terrain Normal Tracking: trackNormal = Normalize( ( normal.x, normal.y, normal.z + 2) ) scaledTrack = alphaTrack * heightRatio alpha.x -= scaledTrack * DotProduct(trackNormal, ForwardVector) alpha.y += scaledTrack * DotProduct(trackNormal, RightVector) Omega += alpha * deltaSeconds Convert 'Omega' To World-Space Mesh->SetPhysicsAngularVelocity(Omega, false)