Hitbox collision only works from one side (only when player enters enemy not if enemy runs into player)

Godot Version

extends CharacterBody2D

var SPEED = 50
var player
var chase

func _ready():
	get_node("AnimatedSprite2D_enemy").play("idle")

func _physics_process(delta):
	if chase == true:
		if get_node("AnimatedSprite2D_enemy").animation != "death":
			get_node("AnimatedSprite2D_enemy").play("run")
		player = get_node("../../Player/Player")
		#var direction = (player.global_position - self.position).normalized()
		var direction = (player.global_position - self.global_position).normalized()
		if direction.x > 0:
			get_node("AnimatedSprite2D_enemy").flip_h = true
		else:
			get_node("AnimatedSprite2D_enemy").flip_h = false
		velocity.x = direction.x * SPEED
	else:
		if get_node("AnimatedSprite2D_enemy").animation != "death":
			get_node("AnimatedSprite2D_enemy").play("idle")
		velocity.x = 0
	move_and_slide()
	
func _on_detection_area_body_entered(body):
	if body.name == "Player":
		chase = true

func _on_detection_area_body_exited(body):
	if body.name == "Player":
		chase = false

func _on_player_collision_body_entered(body):
	if body.name == "Player":
		Game.playerHP -= 1
		
func _on_caminy_death_body_entered(body):
	if body.name == "Player":
		death()
		
func death():
	Game.gold += 5
	Utils.saveGame()
	chase = false
	get_node("AnimatedSprite2D_enemy").play("death")
	await get_node("AnimatedSprite2D_enemy").animation_finished
	self.queue_free()

Question

If I run into the enemy the player is hurt but if I wait for the enemy to run to and collide with the player, the damage isn’t dealt
checking for a collision from both sides doesn’t solve this problem and also causes double the damage to be dealt (logically)
How can I fix this?
I thought about maybe just putting a bool on the collision of both sides and if it’s true (checked from global script), the damage is dealt… but this solution seems to be way to unnecessarily complicated for that task, isn’t it?

So the player doesnt have collision-detection? Are you sure the enemy enters the player-hitbox?

1 Like

I’m pretty sure the enemy enters the player hitbox :thinking:
Rn I only have one collision box for my player though. I wasn’t sure about it but might it be advisable to have a “usual, physical” collision box (for plattforms etc) and a “hurtbox” (for detecting enemy-collisions apart of physical collisions)?
And if so, even if those collision-shapes are the exact same?

Having a second collision box is possible not in this case shouldnt be necessary. Can you provide a screenshot or something of both situations and put print-statements when a collision is detected?