0 votes

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.

Godot version 3.2.3
in Engine by (106 points)

2 Answers

0 votes
by (78 points)
0 votes

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)

by (1,436 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.