Need example for enemy AI in beat'em'up game

For questions about using Classic.

Post » Thu May 05, 2011 11:34 am

Hi everyone! I'm currently working on a beat'em'up game, like good old "Double Dragon". I'm noob in Construct so I need help with enemy AI. I want enemy to come to a certain distance towards player and then attack him in melee. In fact enemy must chase player, get close to him, attack, continue chasing if player got away. If anyone could help with example .cap file my gratitude will be epic :mrgreen:
B
54
S
11
G
4
Posts: 250
Reputation: 5,074

Post » Thu May 05, 2011 6:43 pm

Since I'm new it would take a long time to make an example up, but you should be able to detect whether the enemy is close enough using something like this:



That's what I used in my rpg to detect whether a caveman is close enough for the hero to talk to. As for chasing I'm working on the same thing, experimenting with bullet and 8-dir behaviors. Leaning towards bullet. You can set the enemy's angle towards the player every X ticks and set it to move forward till its in range.
B
3
G
1
Posts: 23
Reputation: 521

Post » Thu May 05, 2011 8:22 pm

You could simplify that by using sprite -> pick by comparison -> distance(.x, .y, Sprite2.x, Sprite2.y) is less than however many pixels. You could also use a pick closest condition with that to make sure you get the closest one.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Thu May 05, 2011 8:30 pm

Will your game be on a single platform like Streets of Rage or Final Fight, or will there by vertical movement like Double Dragon? Vertical movement, such as how the enemy's in Double Dragon climb up and down ladders to get to you, will require more complex AI.
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Thu May 05, 2011 8:37 pm

[quote="Mulkaccino":11zysxf8]Will your game be on a single platform like Streets of Rage or Final Fight, or will there by vertical movement like Double Dragon? Vertical movement, such as how the enemy's in Double Dragon climb up and down ladders to get to you, will require more complex AI.[/quote:11zysxf8]

That said, the distance for a 3D displacement would be something like:
[code:11zysxf8]sqrt((Player.X - Enemy.X)^2 + (Player.Y - Enemy.Y)^2 + (Player.ZElevation - Enemy.ZElevation)^ 2[/code:11zysxf8]

You could then use the Line Of Sight behaviour from the base of the enemy to the base of the player to see if there are any obsticals in the way, if not then have them move towards the player.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Thu May 05, 2011 9:46 pm

[quote="Arima":4nkcuavt]You could simplify that by using sprite -> pick by comparison -> distance(.x, .y, Sprite2.x, Sprite2.y) is less than however many pixels. You could also use a pick closest condition with that to make sure you get the closest one.[/quote:4nkcuavt]

Awesome I'll do that!
B
3
G
1
Posts: 23
Reputation: 521

Post » Fri May 06, 2011 9:18 pm

Thanks a lot! I'll try.
B
54
S
11
G
4
Posts: 250
Reputation: 5,074


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests