This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+3 votes

Hello,
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")):
    mode = MODE_STATIC


if Input.is_action_just_released("touch"):
    mode = MODE_RIGID

print(mode);

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

in Engine by (31 points)
edited by

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.

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

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.

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

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

I have the same issue.

2 Answers

0 votes

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

by (50 points)
+1 vote

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
apply_central_impulse(Vector2.ONE)

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

by (60 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 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.