#Collision error?

7 messages · Page 1 of 1 (latest)

opaque hound
#

so i want to decrease enemy health if it got hit by player bullet but when i check the debugger didn't print anything when it entered the enemy

extends CharacterBody2D
class_name Enemy

@export var max_health : int = 5
@export var health : int

func _ready():
    health = max_health

func _process(delta):
    if health <= 0:
        get_parent().queue_free()

func _on_area_2d_body_entered(body):
    print(body)
cunning plover
#

what's your bullet's type?

#

also, I'm pretty sure you have to enable monitoring for your Area2D, this can be done with $Area2D.set_monitoring(true) in the _ready() function, read more here

cunning plover
#

also, since you are starting, I suggest also reading the documentation on the stuff you are using so you don't have to wait for someone to answer. The documentation is available thru the editor so all you need to do to get docs for, let's say, Area2D, is to right-click it in the editor, and click on "Open Documentation", It can contain a solution to your problem. 😀

opaque hound
#

ok thanks

#

oh i just realized that you also need to assign the collision mask and layer in the area2d