Is there a better way of perform the enemy behabiour?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By albertosanchezm


I’m just starting with Godot, seems a lot of tutorials and those kind of stuffs.

The point is that more or less I understand the basics, so I decided to start with a very simple game, just a Player and a Skeleton (the enemy). The mecanics is to fight to melee (with swords). So, the Skeleton is wandering around (with a Path2d) until it detects the Player. Then it goes toward it and attack him.

I have created several Area2Ds for:

  • Hitbox: to detect when Player sword hit it.
  • PlayerDetection: to detect when the Player is at sight.
  • AttackDistance: to detect when the Player is close enought to attack him
  • AttackArea: to detect if the Skeleton sword hits the Player.

Now, my question is… are those areas necesaries or is there a better way to do this?

Thanks in advanced.

:bust_in_silhouette: Reply From: slavi

The Enemy script can have a link to the Player.
So in the script you can calculate the distance between them, and determine whether the player is at a visible distance and whether he is close enough to hit.

You can also do without a hitbox if you check the distance for the end of the strike (for example, if the player managed to move away during the swing, then the distance is greater than the prescribed one and the damage is not applied)

Thanks… but how I connect both scripts? Using get_node()?

albertosanchezm | 2023-03-25 16:44

You can create a variable, write the Export attribute before it, and then connect the Player scene to this variable through the Inspector Panel

slavi | 2023-03-26 07:09

In any case, this is just one of the options, in fact, you need to use what suits you best

slavi | 2023-03-26 07:11

Thanks a lot

albertosanchezm | 2023-03-26 14:58