RigidBody2D does not behave like a RigidBody after setting it from MODE_STATIC back to MODE_RIGID

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

I’m new to Godots physics engine; I wanted to make a game where everytime the player touches the screen the playerNode(a RigidBody2D) behaves like a StaticBody2D, otherwise the node should behave like a RigidBody2D.
My Code below doesn’t work. When the screen gets touched the playerNode behaves like a StaticBody2D, but if I stop touching it doesn’t change back to the RIGID_MODE-Behavior.
However, I can see in the console that the value of “mode” changes as wanted, but still theres no gravity or so that gets applied.

My Code

func _physics_process(delta):
if (Input.is_action_just_pressed("touch")):
if Input.is_action_just_released("touch"):
	mode = MODE_RIGID

What makes it even more confusing is that if I switch mode = MODE_STATIC and mode = MODE_RIGID it works, but not the other way around.

Maybe you could have a “toggle” state? When the player presses the screen (i.e. the function Input.is_action_pressed() is used), if the current mode is MODE_RIGID, then change it to MODE_STATIC.

Ertain | 2019-12-04 00:12

This doesn’t work too :/.
After the player is set to static it also does not interact with other (rigidbody)-nodes.

obstsalat | 2019-12-04 13:22

I would suggest you make it kinematic instead of static, as a workaround, to test if it works. However if Godot allows it but it doesn’t work, there is probably a bug to report. Either it’s really a bug, or it’s just not supported by the underlying physics engine.

Zylann | 2019-12-04 21:45

Any news on this? I have a similar problem:

I made a chain with Rigidbody2D and PinJoint2D.

The first Rigidbody2D is set to mode ‘Kinematic’ in the editor, the others are all set to ‘Rigid’.

Setting the ‘Kinematic’ Rigidbody2D of that chain to ‘Rigid’ and then back to ‘Kinematic’ during runtime, breaks the PinJoint2Ds…

k3nzngtn | 2020-05-01 20:09

I would recommend setting up a different thread for your question.

Ertain | 2020-05-01 23:41

I have the same issue.

anssiko | 2020-11-18 10:19

:bust_in_silhouette: Reply From: ItsYoBoi

In the settings of the RigidBody, you can make it appear like a static body. Sorry if this doesnt help

:bust_in_silhouette: Reply From: k3nzngtn

I think you have to apply an impulse to the rigidbody after changing the mode back to MODE_RIGID, for example:

mode = RigidBody2D.MODE_RIGID

I found the answer here: https://kidscancode.org/godot_recipes/physics/rigidbody_drag_drop/

I used this method in one of my projects, and it’s working fine. :slight_smile: