#Need help with detecting when a Rigidbody2D is in an Area2D

12 messages · Page 1 of 1 (latest)

autumn steeple
#

I have a scene that is instanced by a node (turret shooting bullets).
The bullet hierarchy is the following:

Area2D (script attached)
-CollisionShape2D
-Node2D
-ColorRect

The script attached to the Area2D is the following:

extends Area2D

var timeUntilDelete = 1
@export var col : Area2D
var velocity : Vector2


func _process(delta):
    position += velocity * delta
    
    if timeUntilDelete > 0:
        timeUntilDelete -= delta
    else:
        queue_free()
    
    pass


func _on_body_entered(body):
    queue_free()
    pass


Everything works, except for the collision. I have tried to follow some tutorials and refer to the 4.1 docs, which have not helped at all. I have the Area2D's body_entered signal attached to itself for the script.

How do I actually make this work?

idle magnet
#

what do your collisions layers for the Area2D and the Rigidbody2D look like?

autumn steeple
idle magnet
#

do they have any layer masks set?

autumn steeple
#

They both have 1 set for that too

idle magnet
#

can you take a screenshot of both? That sounds like it should be working, but just to check

autumn steeple
#

for RigidBody2D

#

for Area2D

idle magnet
#

okay the layers aren't the problem, I'm just trying to think of what it could be

#

are you sure you connected your signal correctly?

autumn steeple
#

I believe so. The Area2D's body_entered signal, which is connected to its own script as _on_body_entered(body)

#

I figured it out - I had the CollisionShape2D set to Disabled like a goof. Thank you for the help!