Enemy following and aiming


#1

How to create an enemy that follows and aims and shoots when the player is near?

Thanks in advance :slight_smile:


#2

@eggtartaurus Think about it in simple terms.

What do you want to do? From your description, break it down in simple tasks instead of a long sentence.

Each task becomes a condition and an action, an sometimes they become embedded or nested into another condition / action event.

For example:
When Player is Near

  • Enemy follows Player (changes Enemy position based in Player position within a distance)
  • Enemy aims Player (changes Enemy angle / direction based in Player position within a distance)
  • Enemy shoots Player (spawn bullets; other object)

Now, what is the simplest idea you can visualize for an enemy finding out about a Player in the vicinity?

For me is that If the Enemy had a range of vision where the Player can enter, it would alert the Enemy.

Usually a field of vision is sort of a cone shape, if you’re doing a top down game, it would be a triangle with the top cut off. This shape could be a real sprite you can hide (but it will be “solid” for collisions) that you can attach to the enemy for example. And if the Player collides / touches that shape, then the enemy will activate the other actions that depend on that.

For shooting and aiming look at the GDevelop online examples, there’s one for shooting bullets, and many other things: https://gdevelop-app.com/game-examples-starters/

There’s even a tutorial to make a tank shooter with similar qualities that cover all of the things you might need: http://wiki.compilgames.net/doku.php/gdevelop5/tutorials/tank-shooter

So if you solve each part of the behavior for your enemy, separately, once you’re done you’ll be able to adapt the stuff you learned. It just takes time. Cheers :wave:


#3

Something similar in the link i’ve upload few days ago


#4

What if i want the enemy to look at the player by flipping horizontally?