Latest Fixes: Pathing for Pixel-Accurate Movement

Today was focused on getting the monsters to behave as intelligently as they did back when movement was tile-based.

  1. Monsters uncrowd when they are overlapping (should pretty much never happen in general, but sometimes they spawn in the hitbox of another creature). If an intersection is detected between two creatures, they get an override that compels them to move away from each other for a few frames.
  2. Cardinal directional movement replaced with simple vectors, to allow for diagonal movement.
  3. When monsters have a line of sight and can walk directly to a hero, they use 8-way movement to get there. I added a bit of tolerance to the check to prevent the monster from zigzagging when on the same X or Y coordinate.
  4. Without line of sight, the monsters fall back on pathfinding (that is, if the monster is intelligent enough.. more on AI changes in another post). Just like with direct walking (which I call Gauntlet Movement in the code), it uses 8-way movement. This was really easy to do with my existing path mapping: it just checks the 8 adjacent tiles by including directions, rather than only the 4 adjacent tiles in cardinal directions.
  5. When monsters are in melee range, they can attack in 8 directions.

A quick word on diagonal movement. In many games with two-dimensional movement, the X and Y movement vectors simply get combined, and not adjusted for the trigonometry. Bishop movement becomes unnaturally faster than rook movement in this case. Think Doom II or Secret of Mana.

Traditional diagonal movement just combines X and Y to give you this nice diagonal reach.
Traditional diagonal movement just combines X and Y to give you this nice diagonal reach.
The "proper way" to do it adjusts diagonal movement to about 70%.
The “proper way” to do it adjusts diagonal movement to about 70%.

After spending so long with these games, my adjustment to trim diagonal speed actually feels like a real debuff. It seems slower even though it’s the same speed. For now it’s still in there, but I’m not sure what I’ll do later. A friend suggested the fast diagonal movement be a powerup.

2 comments

  1. Recently I’ve encountered that diagonal problem as well when testing out movement. Basically what I did was normalizing the vector and multiplying it with movement speed… Which makes sense logically, you don’t magically speed up in RL because you suddenly walk diagonally. But because it was also only 8-directional movement and not analog, it felt like a weird slowdown whenever I moved diagonally.

    It feels much slower normalizing the vector than it feels faster in comparison to simply adding both vectors. You say “After spending so long with these games….” – Do you think that’s simply because you (well, and me too) are perceiving this as a debuff because you played other games where it’s simply faster? Or is that a general thing?

  2. Exactly, after playing so many games with “diagonal magic” it’s just an expectation at this point. As a quick update, I’ve currently got all creatures using diagonal magic for walking, and it feels great. It’s not so much of a powerup if the monsters can do it when they chase you. One place I do normalize the vectors is vision range and projectile attacks.

Leave a comment

Your email address will not be published. Required fields are marked *