In one of my games, I seek to make the player a loose object that is held vertically using torque forces in a stable manner.
It works fine, but I am not sure how I will be able to predict when to cut out the forces in time for it to right up perfectly. See, when it is not on the correct angle and is pushed out, it overcompensates and wobbles a bit before settling. And when the player capsule hitbox drags on the ground, it is an intentional desire for it to appear to “lean” into its motion. But I want to eliminate its wobbliness, as it can get intense and cause the player to spin uncontrollably and break completely when the player moves around chaotically.
How can I smooth out the rotations and prevent it from breaking when bent past a certain angle?
Some code:
var rot = this.entity.getRotation();
if (rot.x > 0){
this.entity.rigidbody.applyTorque(-this.angler * rot.x,0,0);
}
if (rot.x < 0){
this.entity.rigidbody.applyTorque(this.angler * -rot.x,0,0);
}
if (rot.z > 0){
this.entity.rigidbody.applyTorque(0,0,-this.angler * rot.z);
}
if (rot.z < 0){
this.entity.rigidbody.applyTorque(0,0,this.angler * -rot.z);
}