Animation issues and Pathfinding

Get help using Construct 2

Post » Sat Dec 14, 2013 7:32 pm

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!
Posts: 78
Reputation: 606

Post » Tue Dec 17, 2013 5:30 pm

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
                  If Enemy.XDirection = 0 | (here you would display the enemy standing still)
                  If Enemy.YDirection = 0
                             If Enemy.XDirection < 0 | (face the enemy to the left)
                             If Enemy.XDirection > 0 | (face enemy to the right)
                             If Enemy.YDirection < 0 | (face enemy up)
                             Else                                | (face enemy down)
                 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.

sgtwombatstudios2013-12-17 17:32:29
Posts: 64
Reputation: 1,032

Return to How do I....?

Who is online

Users browsing this forum: David181, istero, webebiz and 1 guest