Area 2D fails to detect Rigidbody 2D, on_body_entered not triggered

Godot Version

4.2

Area 2D not Detecting Rigidbody 2D or triggering body_entered signal

Hello. My apologies if this topic is basic, but this is my second day working with Godot. After completing the “Your First Game” in the documentation, I attempted to make a Pong game.
Paddle 1 moves and is controlled by the user (works as expected)
Paddle 2 follows the ball (most of the time)
The ball moves in a random direction at the start (also works)
However, the ball does not bounce off either paddle
image
Paddle, Paddle2, and Ball are all separate scenes that were loaded into the main scene which is why their children are yellow in the attached image (I think)

What I’m attempting to do:

func _on_body_entered(_body):
	hit.emit()
	hide() #Visual confirmation that the signal was triggered

“hit” is a signal that is picked up by the Main node which does this:

func _process(_delta):
	if $Ball != null:
		$Paddle2.ball = $Ball.position
		$Paddle2.ballocity = $Ball.velocity


func _on_paddle_hit():
	$Ball.directional = -1
	print("This statement works")

func _on_paddle_2_hit():
	$Ball.directional = -1
	print("This statement works")

The code in _process works, and it’s what controls the motion of Paddle 2 (which does function as expected - at least most of the time)
Which is why I expected $Ball.directional = -1 to work as well. What does directional do?

Ball:

func _process(delta):
	position += velocity * delta
	position = position.clamp(Vector2.ZERO, screen_size)
	if position[1] >= (screen_size[1] * 0.96) || position[1] <= (screen_size[1] * 0.04):
		velocity.y *= -1
	if position[0] <= (screen_size[0] * 0.03):
		hide()
	if directional == -1:
		velocity.x *= directional
		directional = 1

It simply inverts the x component of the ball’s velocity (and is reassigned to the value 1 as it was originally defined)
I originally tried doing something else in main

$Ball.velocity.x *= -1

But when that didn’t work I tried the approach of manipulating other variables instead, because it worked for Paddle #2

I’m really at a loss, even after reading the docs, double checking the scripts in the “Your First Game” project (which also uses an Area2D to detect a Rigidbody2D), and that works but this doesn’t and the difference is… nothing? I’m just really confused.

And yes, The monitoring property of Area2D is on, the signal is connected, and they are set to the same collision layer of 1, with a mask of 1 for Area2D. Which is why I’m really confused as to why the collision isn’t triggering at all.

I will answer any other questions ASAP and I would really appreciate the help.

Thank you for your time

2 Likes

Maybe you have changed the collision layer or collision mask of any of your paddles or ball?

The collision layers (and mask) of all three objects is set to ‘1’. I was planning on showing it but I was not allowed to add more than one image to my post. The properties of the paddle and ball are shown below:

I tried on my computer and my Area2D successfully detects rigidbody2D…you can check your collision2D’s shape and collision layer and mask…and make sure your body_entered signal is correctly connect to your script

As you can see above, the collision layers & masks for the padlde (left) and ball (right) are set equal.
The signals are set like so:

  • The Area2D signal body_entered is connected to the Paddle.gd script, which emits a signal called hit. hit.emit() This signal is connected to the main node script, main.gd, which uses $Ball or get_node("Ball") to change the ball’s x-velocity.
  • The problem is only that a collision is not detected. As seen in the paddle script:
func _on_body_entered(_body):
	print("The paddle detected another 2D Body")
	hit.emit()
	hide() #Visual confirmation that the signal was triggered


I should be even receiving a message in the console that the signal was triggered but I receive nothing

Update: CollisionShape does not move with the Ball?

In a debug attempt I added the ability to move the paddle left and right, and found that the ball changes directions whenever the paddle crosses the point that the ball originated from. I have absolutely no idea why that would be the case or how it would even work, because the collision shape needs to be moving with the ball in order to bounce off the sides of the screen properly…

What is going on?
Untitled video - Made with Clipchamp

hello brother,did you solve this problem?I have the same problem. when characterBody2d collision RigidBody2d, RigidBody2d’s on_body_entered doesn’t trigger