Wednesday, April 3, 2024

Enemy AI part 2

For the enemy to attack, the player needs to have a hurtbox and some stats. That's the first thing we are going to do.

- Add a hurtbox and a stats child node to your player

- As we did with the enemy, we need to connect the no_health signal from the player stats too

- Yes, we also need another signal connected to the player for the hurtbox Area entered too

* After connecting this signal, you should have two, one for the hitbox to the area (for the animation effect), and one for the hitbox to the player (for the damage).


- After that, add the variable and the function for the player to update their stats
`onready var stats = $Stats` and

```
func _on_Hurtbox_area_entered(area):
    stats.health -= area.damage
```


- So, the player can be hurt, but the enemy doesn't have a hitbox, it's time to change that. Add a hitbox child node to your enemy

* Don't forget its shape, for now we will just attach a circle shape (will update this according to enemy's attacks later)


* It also needs the mask set up properly, 3 = player hurtbox:


With all of that, our enemy can kill the player now. However, the player never exits the area hitbox and the enemy can't repeat the attack until that.


>>> Things to fix: The enemy attack animation and hitbox, and the enemy exiting the area. Both should be fixable at the same time when we do the attack sprite animation part.

>>> Things to fix 2: enemy Sprite Overlap. If there is more than one enemy following you they overlap and you only see one sprite which also affect to colliders.

No comments:

Post a Comment