I have a script called GenericProp that I’m using across lots of scenes in my game. I’m trying to set up collision detection between these props so I can trigger a behaviour.
These scenes will be instantiated at runtime so I was thinking something like:
Because all the scenes of the same type will have this script on it, I thought I could connect the signal to itself. Typing this out now I see how that doesn’t really make sense.
How should I detect collisions between instantiated scenes of the same type in Godot? I suppose I could put the scenes in a group then connect to everything in the group? Something like:
func _ready():
add_to_group("generic_props")
for n in get_tree().get_nodes_in_group("generic_props"):
n.connect("body_entered", _on_body_entered)
Your first example makes sense, the body_entered signals is emitted when two objects collide, your RigidBody in the form of self and the other colliding body as the argument for _on_body_entered.
Could you explain why this doesn’t make sense? Did you encounter an error?