0 Favourites

Simple Enemy AI: Enemies Picking the Same Actions

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

    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.

  • 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.

    CapX: https://dl.dropboxusercontent.com/u/109921357/Enemy_AI_help.capx

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
94 21,761
LaDestitute's avatar
LaDestitute
Unread hot topic
62 7,085
chadorireborn's avatar
chadorireborn
Unread hot topic
58 5,720
BigKid Icarus's avatar
BigKid Icarus