How to rotate a RigidBody by an exact amount of degrees without affecting collisions?

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

I had a game with cars where I used KinematicBodies2D, I rotated them using rotation = value but now that I have wanted to change them to RigidBodies2D I am having complications.

If I try to directly change the rotation with rotation = value it works fine until it collides with objects as it does so in a weird way and goes through them sometimes. I have also tried using angular velocity with which it collides well but I don’t know how to make it rotate exactly the degrees I want.

So I would appreciate if you tell me a way to rotate a rigid body an exact amount of degrees without damaging collisions.

:bust_in_silhouette: Reply From: Stupido

Maybe this is the answer you are looking for:

by kidscancode

:bust_in_silhouette: Reply From: Andrea

are you trying to do this rotation instantly, or gradually?
If gradually i suggest to use add_torque() and maybe use a PID approach, something like

func PID(delta):
 var P=(rotation-angle_target)*proportional_param
 var I=(rotation-angle_target)*i_time*integral_param
 var D=(previous_step_rotation-rotation)/delta*derivative_param

(if it seems too complicate, the P term is probably more than enough for a simple project)