Stopping sideways rotation

Hi Al!

I am trying to stop this sideways drifting rotation -

Locking the y rotation doesn’t work that well because it’s a global effect, so when the object hits the incline it gets messed up.
Apart from that I have tried to apply an opposite rotation force locally but theres something not right about that (I think it’s my script actually :frowning: )

Does anyone know how I could stop this?
Thanks!
Pete

Oh and here’s my script -

    public Rigidbody RB;
    public Transform ThisObj;

    void Awake(){
        RB = this.GetComponent<Rigidbody>();
        ThisObj = this.GetComponent<Transform>();
    }

    void FixedUpdate () {
        Vector3 LocalTorque = ThisObj.InverseTransformDirection(RB.velocity);//get local rotation
        RB.AddRelativeTorque (new Vector3(0,-LocalTorque.y,0));//apply opposite to counter the roation
    }

Try adding a configurable joint which can be configured in world or local space. Then lock the axis (of the joint not rigidbody) and see if that get’s you closer to what you want.