Collisions between two Areas2D, one as the player and one as "coin"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Expezo
:warning: Old Version Published before Godot 3 was released.

I’m new to Godot and doing my first game. It’s pretty simple, but even though I can’t handle one thing. I need a collision detector, simple signal that destroys one of the nodes when it’s space is colliding with player’s space, and gives points to the player. I’ve tried a lot with methods like the one shown in “Space Shooter Demo”, using Areas2D and CollisionShapes2D, but nothing happens. Do you have any ideas what have I missed?

Give more details of your scene setup (areas, shapes, masks and layers, in particular), because it should work with signal or overlap detection.

eons | 2016-12-20 17:31

:bust_in_silhouette: Reply From: ohmi

I’ve quickly tried it. What you need to use is a “connection”.

In the standard layout next ot the inspector tab there is a node tab, where you can select to connect the on_Area2D_enter function to your script. This will create a function in the Script which fires if another Area2D enters the connected Area.

My Code:

extends Node

func _ready():
pass

func _on_Area2D1_area_enter( area ):
print(“Too close”)
get_node(“Area2D1”).queue_free()

I knew it before, but after some more thinking I realized, how important is all this parent-child stuff. Simply adding everything to the same parent was enough to get everything working properly. Thanks again :slight_smile:

Expezo | 2016-12-21 21:28