#struggling to get collision detection to work with rigidbodies

1 messages · Page 1 of 1 (latest)

winged trout
#

heya, i cant figure out why my collision detection isn't working. im trying to make two objects merge into a new node like in suika game or 2048. I've followed a couple tutorials as well as tried using chatGPT to explain what i could be doing wrong but i cant figure it out. i have a rigid body parent node with a sprite and a collisionpolygon2d, i have connected the body entered signal and tried printing text to test the collision.

extends RigidBody2D

@export var node_value: int = 1
signal merged(new_node)

func _ready():
body_entered.connect(_on_body_entered)

func _on_body_entered3(body):
print("Body entered:", body)

func merge_with(other):
# Create a new node with the combined value
var new_node = preload("res://scenes/chipruby.tscn").instantiate()
new_node.node_value = node_value + 1
new_node.position = position.lerp(other.position, 0.5) # Place between the two nodes
emit_signal("merged", new_node)

func _on_body_entered(other):
if other is RigidBody2D and other.node_value == node_value:
merge_with(other)

# Free the old nodes
other.queue_free()
queue_free()
fickle carbon
winged trout
orchid thorn
#

func _on_body_entered3(body):
print("Body entered:", body)
Is this a syntax error with the _on_body_entered3

winged trout
orchid thorn
#

Yeah

winged trout
#

oh i dont know honestly

orchid thorn
#

It might be

#

Try deleting the 3 from that and try it again

winged trout
#

still not seeing any print

orchid thorn
#

Hmm

#

Have you considered using the area 2d as opposed to rigid body 2d?

winged trout
mystic slate
winged trout
mystic slate
fickle carbon
mystic slate
#

did not knew that, thanks again :)

cunning canyon
#

As yesfish said above, you can override this and have RigidBody2Ds report on contact by enabling the contact_monitor property of the RigidBody2D as well as specifying a non-zero max_contacts_reported