0 votes

Hello,

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.

Godot version 4.0
in Engine by (19 points)

1 Answer

0 votes

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)

by (58 points)

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

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

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

Thanks a lot

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.