Rigidbody Physics Stabilization?

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);

I sort of do this with this project https://playcanvas.com/editor/scene/685099

Press space to make it appear in the appear at a random rotation and it self rights.

TLDR is to use damping based on how close it is to the ideal rotation.

My actual project might help @yaustar!


I strongly encourage intense and random pressing of keys. At one point you will get the feel of how the player physics move and (Hopefully) you will encounter the glitch!

Had a quick look and looks like some damping is needed on the torque or the values to be tweaked or adjusted so that it doesn’t over wobble.

Thank you, your help is appreciated.

Ah, with my project https://playcanvas.com/editor/scene/685099

Press R to make it a random rotation
Press Space for it to self right itself