+1 vote

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?

in Engine by (695 points)

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

I tried all the time changing the rotation with settransform() or setglobal_transform() and never tried it the easy way :-)

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?

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

2 Answers

0 votes

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.

by (45 points)
0 votes

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...

by (14 points)

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

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 Frequently asked questions and 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 [email protected] with your username.