How do I reset the rotation of a RigidBody2D back to original rotation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By puppetmaster-
:warning: Old Version Published before Godot 3 was released.

I have a RigidBody2D with mode Character.

Sometimes I change the mode to Rigid and let the body rotate physically.

But when I want to change the mode back to Character the rotation should also go back to 0.

How can I do it?

I’m not sure I understand your question but it sounds to my like set_rot(0) would work?!

umfk | 2016-03-13 14:33

I tried all the time changing the rotation with set_transform() or set_global_transform() and never tried it the easy way :slight_smile:

It seems set_rot(0) would do the job but when the rotation is to fast it doesn’t stay on rotation = 0

I do it in this order

body.set_mode(2)
body.set_rot(0)

Is there a possibility to stop the rotation without setting mode to static?

puppetmaster- | 2016-03-13 20:23

Well, you can just set_rot(0) on both this and the next frame, right?

Bojidar Marinov | 2016-03-19 16:26

:bust_in_silhouette: Reply From: del

Do you mean the rotation you had before you changed the mode? In this chase you could just store the old rotation in a variable and assign it when you’re changing back.

:bust_in_silhouette: Reply From: gitnob

If you want to slowly rotate back your rigid body, then you can write something like:

# restore up rotation after collisions
var rotY=get_transform().basis.y
var rotAxis=rotY.cross(up)
var torqueAxis=rotY.cross(rotAxis)
#print(torqueAxis,rotY)
apply_impulse(torqueAxis,rotY*0.01*maxTorqueFactor)
apply_impulse(-torqueAxis,-rotY*0.01*maxTorqueFactor)

where up is a Vector2 of the up direction and maxTorqueFactor must be set to an appropriate float value…

Thank you for your answer. I’ll check if it helps.

puppetmaster- | 2016-03-20 21:02