Simple Enemy AI: Enemies Picking the Same Actions

Get help using Construct 2

Post » Sat Jun 20, 2015 3:50 am

https://dl.dropboxusercontent.com/u/290 ... stadv.capx

Image

I am creating a simple overhead engine. I have a simple random 4-way movement enemy. Ideally, multiple instances of the same enemy would be moving about differently (see the picking different speeds option - just an example and not final), so it wouldn't look so mechanical and choreographed.

However, the enemies, while they do indeed move in different directions, pick the same speed while moving, which gives off that mechanical feeling I described.

While I dislike begging for answers, I would appreciate it if someone could help out. I thought it would be related to a For Each(enemy) event, but switching the order of conditions causes the movement to bug out pretty hard. Perhaps something with UniqueID? I am unsure.

Thank you for any and all help in advance.
Check out my VGM on my soundcloud page!
Video-Game Music: E.C.2151
B
9
S
3
G
2
Posts: 194
Reputation: 1,713

Post » Sat Jun 20, 2015 8:22 am

Think your problem is with the "Move" variable and the use of waits. My advice is to not use waits inside your code for something like this, because you can risk running into problems that are really difficult to debug, since its near impossible to figure out where in your code problems occur when you cant really track when thing triggers, you can run into some really annoying problems when you expand your games and they start to get more complicated. Personally I try to avoid any waits whenever possible, and only use them when a workaround for C2 requires it, or if the game actually need it for something, which is rarely the case.

Anyway here is a modified version, which uses different speeds. I have added a Timer behaviour to the enemies instead of using waits, the benefit of that is that you can easy track where things go wrong as they trigger when the time is up. And the code inside them wont execute before that happens.

Image

CapX: https://dl.dropboxusercontent.com/u/109921357/Enemy_AI_help.capx
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Mon Jun 22, 2015 3:07 am

Thank you for the modifications. I seem to remember years ago similar warnings about the Wait command and its potential bugginess (truly there are no easy solutions?).

I will try tinkering with the System: Pick options to see if there is more variation I can add to the mix.

EDIT:

I got exactly what I was looking for by using an additional variable, "active" along with a new timer condition, "Activate."

Start of Layout
For Each Enemy
>variable active: choose(1,2)

active = 1
Trigger Once
>Set timer "Activate" for 1.5 (once)

active = 2
Trigger Once
>Set timer "Wait" for 0.0 (once)

On timer "Activate"
>set move to 1

plus what you have above.

This gives a more natural random nature to the enemies if there are multiple enemies on-screen at once.

EDIT: This will need more messing around, because I forgot to make the enemies recognize solids. I know I've seen .capx files which have enemies change their paths when colliding with solids, so I'll have to implement something like that.

You can have an event something like
On collision with solid
>set enemy angle to GetCurrentAngleofMotion - 180

and fiddle with the timers to get the enemy back into the loop of moving. It will bug out if the enemy is between two solid or skirting along the edge of a solid, so keep on testing.
Check out my VGM on my soundcloud page!
Video-Game Music: E.C.2151
B
9
S
3
G
2
Posts: 194
Reputation: 1,713


Return to How do I....?

Who is online

Users browsing this forum: AndreasR, karthikavnair, Rable and 10 guests