0 votes


I'm a new learner of Godot and Im trying to use body_entered signal to detect collision between a RigidBody2D object and a StaticBody2D obstacle, BUT it does not work and I don't know why. Please help me with this issue. Here is my code and I did not know which is wrong to let it work:

extends RigidBody2D

func _ready():
  connect("body_entered", self, "_on_character_body_entered")

func _input(event):
  if event.is_action_pressed("move"):

func move():

func _on_character_body_entered():

func _bounce():
in Engine by (20 points)
edited by

1 Answer

+1 vote
Best answer

In order for a rigid body to report collisions, you must enable "Contact Monitoring" and set "Contacts Reported" to a value greater than 0.

Some other comments:

You cannot move a rigid body by setting its linear velocity directly like that. You must apply forces or impulses, because a rigid body is controlled directly by the physics engine, not by you. See Physics Introduction: RigidBody2D and the RigidBody2D documentation for more information.

Also, it looks like you've been using old tutorial material for pre 3.0 versions of Godot. You don't need to set input processing, or use set()/get() on object properties.

Lastly, you don't need to put pass everywhere. It literally does nothing.

by (18,221 points)
selected by

Thank you,

It worked! I found the description of body_entered signal in the documentation as well. For the input process and pass, could you show me where to read more or any tutorial of the update 3.1?

Im Really appreciated for your comments :)

The transition from 2.1 to 3.0 happened some time ago. Basically any tutorial that's less than 2 years old is going to be fine. Older than that and you'll have to change a lot of things.

If you want to learn the engine with up-to-date information, the official docs are by far the best place to start: Documentation: Step by step.

pass has nothing to do with version. It's a command that literally means "do nothing". Putting it at the end of every one of your functions is doing nothing but taking up space. The only time you ever need to use pass is when you need a placeholder for a function body that you're planning to fill in later.

Thank you,

I watched some tutorial and I thought that pass is to end the function :P

Have a nice day!

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.