How to make simple enemy AI (No zombie AI)

Hello everyone :smiley: . Yap~ Just like my title said, I want ask this question. :unamused: Recently, I making like Call Of Duty’s game, graphics was started and made some, but I stuck AI system, this thing… :astonished: How to make enemy shoot near enemy, how to set way point? :confused: Hope have guys help me.

Btw, hope guys can send me example or function process, I don’t want a lot text, because my English so bad, and I easily confused on a lot text. :frowning:

(PS: You can write chinese word here. :wink: )

Example is included with GDevelop.
File => Open an example => BasicArtificialIntelligence.gdg

(Jamming)… … :astonished: :astonished: :astonished: ,Er~Thanks dude and sorry I miss that example… :smiley:

I back to AI’s waypoint problem, I very confuse now… :confused: AI’s waypoint is using path, pathfinding, or physic??? :confused: Also I don’t know how to use them. :frowning:

The AI example is using the stock movement actions (forces) to move the AI objects, I don’t think any physics engine involved in the actual calculations but I can be wrong. But in case you plan to make more advanced AI, you probably better off with pathfinding,

I would be more than happy to explain how to make an AI but you just mentioned before too much text may confuse you

And I can be very confusing even if english is your first language :laughing:
So, I’m not sure if it worth the time to explain in detail how the AI works or how to make one.
It is not that simple really, if you are new to game development in general, you may need to get familiar with different concepts first to get the idea.

But let me try to explain the example in a simple way:

In the example each enemy constantly shooting the “view” object toward the player. If the ‘view’ object is in collision with the player it means, the player is visible to the enemy. If the ‘view’ object is in collision with an obstacle, the ‘view’ object get destroyed and so, if the player is behind the obstacle, the player is not going to be visible to the enemy simply because it is not colliding with the ‘view’ object.

If the player is visible to the enemy, the enemy get alerted using a variable. Object linking helps with the decision which enemy get alerted, which enemy can see the player. (I can explain in detail how object linking works but let see first if you understand the basic concept)

If an enemy is alerted because the player is visible to it, the enemy simply start moving toward the player and that’s it. After some time, if the enemy can not see the player any longer, it is going to stop.

Finally, if the enemy and the player is in collision with the obstacle the example is using the separate two objects event to simply keep the enemy and the player away from the obstacle.

Thanks you so much, ddabrahim. :smiley: My currently game’s concept is like Battlefield combined Call Of Duty(Just little like), choose your kit, and battle for skirmish , but without vehicles. So I want making alliance AI and enemy AI like Call Of Duty. :wink: (PS: I know this is not very simple, but I want try new thing. :slight_smile: )

I continue post AI question here. :slight_smile:
How to let AI can choose the new waypoints their want?

How to let AI when waypoint is end way, will continue moving not stay current position?

They are my currently problems, hope somebody can help. :slight_smile:

(PS: That soldier is my next project’s character, called “Scout”. :wink: )

In case you are using the Path behaviour, you can just simply change to a new path whenever you want.
In case you want it to be random path, the easiest way to go is name the paths you have created using numbers and simply generate a random number, then convert the number to string using the ToString() expression.
So basically when you switch to a new path, as path name you can do ToString(Random(5)).
It is going to pick a Random number in range 0-5 and in case the name of path is in range 0-5, it is going to pick a random path…

In case you are using the Pathfinding behaviour, the only thing you need to do is change the position of the destination whenever you want and the Pathfinding going to handle the rest…

In case of Path behaviour there is a condition to test if the object is reached the end of the path, then you can pick a new path or invert the path. So basically if you want to create a patrol which is moving back and forth on a Path, you can just invert path whenever the object reach the end of it.

In case of Pathfinding, there is a condition to check if the object reached it destination, if it does you can just set a new position for a destination. But in case you want to create a patrol you need to make sure there is no obstacle between the start and end position otherwise the pathfinding may pick an alternative route around the map and just ruin the patrol unless it is what you want, to make the patrol keep walking up and down on random routes. In that case pathfinding is the better option imo.

1 Like

Thanks ddabrahim. :smiley: I go to check it up. :slight_smile:

I have problem here. :astonished: I stuck about AI attack range and each action, I make a AI with view radius, I just want AI attack his view radius’s enemy, not all enemy(included outside his view radius’s enemy). :open_mouth: Also I want let AI do their each action not together(The same one object). So how can I do. :confused:

The problem is that when you working with instances of the same object there is a good chance your program simply doesn’t know which instance you are referring to. Maybe it obvious to you but not so much for a program…

You can solve this kind of problems by using the “For each object” event. This is a special event that is works similar to a standard event except, it is going to test the conditions and trigger the actions individually for each instance of an object.

The other thing you can also try is the Object Linking extension. By using this extension, you can logically link objects to objects, for example when you are creating the view objects in position of the enemy you can link the object to the enemy instance. After when the view object is in collision with the player you can use the object linking extension to refer to whichever enemy instance linked to the colliding view object to do something.

Unfortunately at the moment I don’t have time to explain in detail how to use the For each object event and Object linking extension The actual solution also depends on how did you actually designed your AI.
Maybe someone else can help you with that. If not, I recommend to try to get familiar with the use of this two features I mentioned by looking at the examples and practising.

1 Like

Thanks~Currently I’m student, so I will take a time to test your function. :slight_smile:

I know this is an old post, but it approaches an issue I am trying to address at the moment ([Solved] Approaches for walking an arbitrary board square by square?). I am definitely giving it a try.

I like very much the idea of shooting “view bullets”. How would you define how far they would go in case there is no obstacle to hit?

Thanks!

In case someone else end up here in the future: [Solved] Approaches for walking an arbitrary board square by square? - #6 by Gruk

Very useful info, thanks! I’m glad I scrolled down and found this thread. Definitely learned some significant concepts for the enemy AI. I think one thing I’m unclear about is how to make the enemy do random attacks but I’m pretty sure that ToString(Random) is a clue! :smiley: I think if I set the ToString(Random) to the attack animations of the enemy, it should execute a random attack? Here’s my related thread >
https://forum.gdevelop.io/t/enemy-ai-for-scrolling-beat-em-up-style-game-example-code/25989/5