Animation issues and Pathfinding

0 favourites
  • 2 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Right now, I have all of my enemies "wandering" by traveling to a randomly spawned node on the layout currently.

    However, whenever an enemy is moving up, left, right or down I want their animations to change, so they change direction.

    However, with pathfinding currently, I'm having a really hard time knowing how to create an event to change the animations for it currently.

    It current looks like this:

    Pathfinding Screenshot

    Any help is always greatly appreciated!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would give each enemy four variables, OldX, OldY, XDirection, YDirection.

    When an enemy is spawned and positioned, set Enemy.OldX = Enemy.X and Enemy.OldY = Enemy.Y

    For Each Enemy | Enemy.XDirection = Enemy.X - Enemy.OldX

                               | Enemy.YDirection = Enemy.Y - Enemy.OldY

                      (subevent)

                      If Enemy.XDirection = 0 | (here you would display the enemy standing still)

                      If Enemy.YDirection = 0

                      (subevent)

                      Else

                                 (subevent)

                                 If Enemy.XDirection < 0 | (face the enemy to the left)

                                 (subevent)

                                 Else

                                 If Enemy.XDirection > 0 | (face enemy to the right)

                                 (subevent)

                                 Else

                                 If Enemy.YDirection < 0 | (face enemy up)

                                 (subevent)

                                 Else                                | (face enemy down)

                     (subevent)

                     Enemy.OldX = Enemy.X   

                     Enemy.OldY = Enemy.Y

    This will check every enemy every tick, so it may slow your game down. If it does, you could stagger

    the enemies so it takes 3 or more ticks to check the direction of all the enemies, rather than all of them

    in 1 tick. Let me know if you would need help doing that.

    Also, if you wouldn't need to use Enemy.XDirection or Enemy.YDirection anywhere else in the game, you could make them local variables above the For Each event, rather than each Enemy holding their own copy of the variable.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)