How I do make an advance ai for my action game

Hi and happy new year.
Here’s what i’ve been trying to do for three days now

Melee enemy (six):
If far away from the player it would chase the player, when near it would strafe around the player first then attack.

Its attack would be based on the direction it’s in like if it’s above the player then the attack animation of the melee enemy would use it’s (attack down animation). If it’s below then (attack up animation) would be used and so on and so fourth.

After it’s attack it would go back to strafing having a cd before attack again

Another thing is that the enemy fights in groups so how do I make sure that the enemy takes turns hitting the player.

(Seven) Range:
Opposite of the melee enemy because for the ranged attack. If the player is near the range enemy, the range enemy would move away from the player at a certain distance only. But if the player gets to far from the range enemy then the enemy would chase the player.

Another thing: range enemy should reposition themselves like they are strafing, and if they are like above the player then they should like do their (attack down animation) and if they are above then (attack up animation) and if left, so on and so fourth.

-For now I’m focusing on the movement before the attacks
(six/melee enemy) just goes back and fourth and doesn’t strafe.
Same goes for the Range enemy. They dont even try to run away from the player.

I’m not putting an attack state for both enemies since I don’t know how to make the ai know if its in the left, right, top, bottom of the player

Here’s the code:




Advance thank you for the help. This is really a big problem for me, it’s been causing me a lot of head aches and nosebleed lol. Happy new year again guys :smiley:

I think we should think of this as a behaviour tree instead of packing than all together:

I would suggest a possible solution due to it’s hard for me to go through all your screenshots:

One question though is this top-down or platformer?

First off start with a no-code view of the behaviour:

A simple tree:

If far from player:
Move towards player
If Close to player (attack state should be active here)
If No Team-mates Nearby:
Move to attack
If team-mates around and attack
Coordinate and attack

Move towards player:
You could turn off collisions checks when far off and off screen to improve perfomance

To check if teammates are nearby, you could:
Pick nearby entities, Check if object state is also attack and check if the number of picked instances is greater that 0 (this is useful and you could also use this to specify a minimum number of ais that work together)

For checking the direction of the player: its simple x and y comparisions with width and height of the ai taken into account. (I recommend you just use CenterX and CenterY)

This need a bit of adjustment based on your game an you needs. I think the above isn’t that accurate but you get the logic (I did this in a rush)

Coordinate and attack:
This may need you to store the last attacked ai (ps you should give the ai ids) and then select all atacking ones/teams (once again ids), remove the last attacked ai and randomly select an ai and attack (remember to set the last attacked ai variable).

These are easier said that done. But I have a lot of expertise with ais so if you have further questions or If I never even answered your questions ask below.

2 Likes

Hello sir, Good day. Sorry for the late reply, it’s just that I’m doing school works right now, exams are nearning. So I will continue making my game in like a few days or the weekends. I just want to let you know, because I have a lot of questions for ai. Also thank you for responding, really your the best.

This video might help you with some things you want to do

2 Likes

Sure! I am open to any question you may have.

2 Likes

@PANDAKO Can you fix this bug in the Dialogue Box extension?

1 Like

well i need help with this

What help exactly? I am happy to help.

Ok im back so here’s questions sir:
The game im making is a top down game sir.
1st: How to make the ai strafe around the player in a certain distance, and if the player gets too far the enemy ai will catch them.

2nd: How can the enemy attack one by one? Like the enemy ai knows if another enemy close by attack so they wont attack for like 1 secs?

3rd: Im also trying to make a friendly ai how can it know who is the player and who isn’t? And how can he kill 1 enemy ai first then proceed to the next etc etc or change to whoever attack the enemy player, but when there is no one to attack he just follows the player

4th: Last one how can the enemy change target. Like for example let’s say P1 attacks the enemy ai, so that enemy ai will lock on to P2 but if player 2 hits him he will switch target and lock on to P2 and etc etc, how to do that?

Sorry if this message is too long and if waited so much, sorry I had an exam for half the month. I still failed the exam even after reviewing for the last past week thou. Anyways thank you for your help sir.

I’ve a few questions:

  1. Firstly, Are the enemies generated or pre-created?

First of all, I think the enemies should all have a variable called ID so you can track them. If they are created during the game set the ID (variable) to the current scene count of the Enemy Object (object).

Answer to your question
1… Just do a simple distance check and do your desired behaviout
2. This is also a distance check but more complicated,
a. Distance Check + Number of Enemy selected > 1 (this means that more than one AI is where the Enemy is). Then use their IDs to plan them
3. It would know because their are different Objects, attack logic only on enemy and assist logic on Player.

If you want me to explain in details with picture references to Gdevelop, I could also assist.

2 Likes

Both there are same areas where enemies are generated after entering this part of the level (this is to reduce lag). And some enemies are pre created because if those enemies need to be killed in order for the next level to be open.

and yes, it would very much help me if you use pic references, because I will be honest with you sir. I am really bad at this coding ai, like I tried watching a lot of vid and somehow due to my strong bad luck at life, it doesn’t work. So if you can please use pictures, and thank you sir. I promise to really credit you in the game, once it is finished.

No need to credit me. It’s always nice helping a friend.

I made a guide project. It isn’t perfect but can be and also used for reference:
https://drive.google.com/drive/folders/1Xo0il_Wfkui3HPZqfmQrGHYKAV5gqh29?usp=sharing

3 Likes

Thank you sir I will update you sir, if still got questions. Really thank you sir.

1 Like