Hello everyone . Yap~ Just like my title said, I want ask this question. Recently, I making like Call Of Duty’s game, graphics was started and made some, but I stuck AI system, this thing… How to make enemy shoot near enemy, how to set way point? 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.
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
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. 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. (PS: I know this is not very simple, but I want try new thing. )
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.
I have problem here. 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). Also I want let AI do their each action not together(The same one object). So how can I do.
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.
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! 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