Enemy AI for a Beat em' up.

Get help using Construct 2

Post » Mon Apr 27, 2015 4:53 am

Making the enemy move, make an action like attacking, I haven't a clue on where to start. :?:
B
15
S
3
Posts: 45
Reputation: 1,040

Post » Mon Apr 27, 2015 12:37 pm

Making the AI can be a difficult process. It all depends on how complex you want it. But I suggest starting with the link below. Luckily there are a lot of tutorials on the subject.

htt ps:/ /www.scirra.com/tutorials/top/page-1?difficulty=1&cat=404&lang=1&dmode=detailed
B
5
Posts: 19
Reputation: 263

Post » Mon Apr 27, 2015 2:14 pm

this might help
https://www.scirra.com/tutorials/1320/p ... enemies-ai

if your game is for 4 directions, up, down, left and right and jump (jump is separate from up) then this tutorial needs a little tweaking for your game since it has 2 more directions for movement (up and down) that weren't taken into account for this tutorial. But concept is still the same.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Mon Apr 27, 2015 4:40 pm

Message: CurioJoe can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
sgn15 wrote:this might help
https://www.scirra.com/tutorials/1320/p ... enemies-ai

if your game is for 4 directions, up, down, left and right and jump (jump is separate from up) then this tutorial needs a little tweaking for your game since it has 2 more directions for movement (up and down) that weren't taken into account for this tutorial. But concept is still the same.


8 Directional movement, top down prospective, I wanna try to make him attack when he gets near the player,
move to the player when player comes close or line of sight, low level stuff ya know?
B
15
S
3
Posts: 45
Reputation: 1,040

Post » Tue Apr 28, 2015 3:38 am

@CurioJoe
Ok. It's a different kind of game altogether from what I was expecting, but I will try to give my initial thoughts on it.

Create sensor objects (which will be invisible) and place them in the intersections. You can make 4 different sensor objects for 4 directions.

For example:
enemy IS overlapping sensor_up
enemy IS overlapping sensor_down
enemy NOT overlapping sensor_left
enemy NOT overlapping sensor_right
For Each: enemy
-> stop moving (use a variable to control AI)

enemy IS overlapping sensor_up
enemy NOT overlapping sensor_down
enemy NOT overlapping sensor_left
enemy NOT overlapping sensor_right
For Each: enemy
-> move up (using 8 direction movement)

enemy IS overlapping sensor_up
enemy NOT overlapping sensor_down
enemy NOT overlapping sensor_left
enemy IS overlapping sensor_right
For Each: enemy
-> move diagonal up right (using 8 direction movement)

and so on, this way, you can create different variations of movement directions (remember, you are using 8 directions, so there are lots of possible movements than just simple left and right in my tutorial). You will still follow the same general logic/idea I used in my tutorial (which is using an instance variable for AI). It would still do you good help to still give it a good read or study my file, it's pretty simple).

Use FOR EACH: enemy to make each enemy behave independently. This way, you have enemies moving in different directions (like patrolling the streets) when you are not in their sight. Then either use Line of Sight behavior or calculate the distance (there is an expression for distance) between you and each enemy to determine if they will chase you, attack you or keep patrolling.

Now for attacks, if you have contact (punches, kicks) and long-range (bullets), you have to further divide the AI, enemies shoot you when you are within a range, they punch you when you are directly beside them. Again, I used the same logic in my tutorial (even if it is for sideview platformer) although I haven't updated my tutorial yet with coding attacks.

To make the AI a little unpredictable, add SYSTEM: Random(1) <= 0.25 meaning it will be 25% chance of happening. It is also in my tutorial file.

Good luck.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Tue Apr 28, 2015 5:47 am

sgn15 wrote:@CurioJoe
Ok. It's a different kind of game altogether from what I was expecting, but I will try to give my initial thoughts on it.

Create sensor objects (which will be invisible) and place them in the intersections. You can make 4 different sensor objects for 4 directions.

For example:
enemy IS overlapping sensor_up
enemy IS overlapping sensor_down
enemy NOT overlapping sensor_left
enemy NOT overlapping sensor_right
For Each: enemy
-> stop moving (use a variable to control AI)

enemy IS overlapping sensor_up
enemy NOT overlapping sensor_down
enemy NOT overlapping sensor_left
enemy NOT overlapping sensor_right
For Each: enemy
-> move up (using 8 direction movement)

enemy IS overlapping sensor_up
enemy NOT overlapping sensor_down
enemy NOT overlapping sensor_left
enemy IS overlapping sensor_right
For Each: enemy
-> move diagonal up right (using 8 direction movement)

and so on, this way, you can create different variations of movement directions (remember, you are using 8 directions, so there are lots of possible movements than just simple left and right in my tutorial). You will still follow the same general logic/idea I used in my tutorial (which is using an instance variable for AI). It would still do you good help to still give it a good read or study my file, it's pretty simple).

Use FOR EACH: enemy to make each enemy behave independently. This way, you have enemies moving in different directions (like patrolling the streets) when you are not in their sight. Then either use Line of Sight behavior or calculate the distance (there is an expression for distance) between you and each enemy to determine if they will chase you, attack you or keep patrolling.

Now for attacks, if you have contact (punches, kicks) and long-range (bullets), you have to further divide the AI, enemies shoot you when you are within a range, they punch you when you are directly beside them. Again, I used the same logic in my tutorial (even if it is for sideview platformer) although I haven't updated my tutorial yet with coding attacks.

To make the AI a little unpredictable, add SYSTEM: Random(1) <= 0.25 meaning it will be 25% chance of happening. It is also in my tutorial file.

Good luck.


Thanks i'll try the best with what I can do. Also, what can I do to make them move faster in a direction, The enemy seems to just jerk in motion making rare progress getting anywhere. I used your numbered AI method, btw.
B
15
S
3
Posts: 45
Reputation: 1,040

Post » Tue Apr 28, 2015 7:51 am

I am not that familiar with both 8 direction and Line of sight behaviors, so I can't really give you good tips that are specific to those behaviors.

Edit:
just checked and tried 8 direction on a blank file. It seems it has same aspects as platform behavior. You can change the max speed, acceleration, vectors using events. So you can actually have walk and run (just code them with different moving speeds). I assumed your question was about moving speed? As for the "jerking motion', not sure what you meant. You also have to adjust the angle of the enemy if they are already being hindered by a solid object (not sure how 8 direction works against solid), but the logic is to adjust the angle they are facing so they can continue moving instead of keeping walking against a wall (like a real person walking against a real wall). If solids don't hinder 8 directions from moving, then no issues at all.

made a simple image
http://s13.postimg.org/9hvgjtkef/image.png

there are lots of combinations for moving for 8 directions.
Imagine the gray areas are roads
red are sensors (can be 1 object or different objects per direction)
arrows are all the possibilities for AI

You can also use timer (time how long it will keep walking in that direction) then when timer ends, set AI to 0 then randomize AI value (like in my tutorial, but base it on how many possible values for AI you use, or randomize just the 4 basic directions). If you don't want timer, alternative is use every x seconds and add 1 to an instance variable, then when said variable = value, set AI to 0. But really I would prefer timer since you wouldn't want to waste a variable when timer behavior is already there for that purpose.
B
16
S
7
Posts: 301
Reputation: 2,726


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests