Collisions between rigid bodies 2d not being registered correctly

Godot Version

Godot 4.2


Hi guys! I can’t seem to be able to create a simple collision counter for a rigid body 2d that is being dropped on bunch of other rigid bodies 2d. Still, the ball bounces off them correctly.

Also, there is a control for the object but it is not related to the problem. I will add it with the rest of the code just in case.

To specify, I already know that:

  1. Everything shares the same layer and mask.
  2. Everything is a child of the root node. They are siblings, all rigid bodies.
  3. The collisions on the screen happen correctly.
  4. There are like 40 rigid bodies and all of them are frozen so they stay in place. None of them are sleeping.

I’d greatly appreciate any help regarding this problem.

Here’s the code:

extends RigidBody2D

var controller
var trigger_pos
var x_coordinate
var y_coordinate
var collision_count = 0

func _ready():
controller = get_parent().get_node(“Controller”)

func _process(delta):
if controller != null:
trigger_pos = controller.get_child_position()
x_coordinate = trigger_pos.x
y_coordinate = trigger_pos.y

func _input(event):
if event.is_action_released(“control1”):
var launchForce = Vector2(x_coordinate * 10, y_coordinate * 10)
self.apply_impulse(launchForce, launchForce)

func _on_body_entered(body):
print("Entered body: ", body)
if body.has_method(“get_name”):
print("Collided with: ", body.get_name())
collision_count += 1
print("Collision Count: ", collision_count)

Read the description of the signal you are using RigidBody2D.body_entered It may give you a hint on what you need to do.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.