[Solved] RigidBody2D body_entered signal does not work

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


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():
:bust_in_silhouette: Reply From: kidscancode

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.

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 :slight_smile:

CrinstalMaiden | 2019-12-13 15:46

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.

kidscancode | 2019-12-13 16:56

Thank you,

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

Have a nice day!

CrinstalMaiden | 2019-12-13 17:22