Rotate a rigidbody to a rotation using angular velocity.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JimmyJohn

I need to rotate a rigidbody to a rotation using angular velocity. This is so I can rotate an object to the rotation of a VR controller. Currently what I am doing is taking the goal rotation and subtracting the current rotation. Since velocity is in Euler Angles, I have to convert the basis to Euler Angles using get_euler().

func _integrate_forces(state):
    var goal_rotation = goal_transform.global_transform.basis.get_euler()
    var current_rotation = global_transform.basis.get_euler()
    var rotation = goal_rotation - current_rotation
    state.angular_velocity = rotation

After rotating past a certain point the rigidbody starts spinning in the wrong way. How do I rotate a rigdbody to a rotation using angular velocity?

:bust_in_silhouette: Reply From: JimmyJohn

I have an alternative to my own answer. I have a StaticBody (any physics body will work) as a child of what I want my goal rotation is. Created a 6DofJoint and connect the RigidBody I want to rotate to the StaticBody. I disabled the Linear and Angular limits and enabled only Angular Spring. I set stiffness to 2 and dampen to 0.05.