so im trying to make a game and i decided to make features, components. now when i try to attack the enemy it doesnt detect it but it does somehow detect the player itself. if any more code needs to be provided, i will provide it
extends Node
class_name AttackComponent
@export var area:Area2D = null
@export var player = true
func attack(damage, knockback):
for body in area.get_overlapping_bodies():
if player:
if body is Enemy:
body.health_component.damage(damage)
else:
if body is Player:
body.health_component.damage(damage)
If all your collision layers are set correctly and it’s still not detecting the enemy, it may be an issue with the attack being too fast and area.get_overlapping_bodies() not detecting the enemy in the current frame. You can try waiting a couple of frames.
i was around the enemy for around 3 seconds before attacking. i was literally coliding with the enemy. theres no way that it couldnt detect the body after 3 seconds