Area2d not detecting the enemy

Godot Version

4.2.2

Question

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.

1 Like

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

oh sorry its fixed it was bcz the AttackComponent was a node and so it didnt have any location in the space so the Area2D was stuck to 0,0

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.