By Wesley Sappington
Hello fellow Conundrum solvers, your favorite coder is back!
So you know how we keep hinting about evil monsters chasing you throughout the Labyrinth? Well, now they actually can chase you!
(I'm sorry about the really zoomed out size - I think I need to make the camera view smaller in general) As you can see, the zombie is chasing me! Can I get Game of the Year Award yet? Lol.
Here's what's going on behind the scenes.
Now, the zombie is smarter than he looks. (At least for now. In the actual game the zombie might be much stupider - but for testing purposes I made him smart.) The pathfinding will avoid stronger barriers and always go for the path of least resistance.
As you can see, the pathfinding (blue line) avoided the brick and went for the dirt. That's because dirt is obviously easier to break than brick.
Things were not always this easy.
The utopian algorithm you see above was not always the wonderland it is today. I had numerous hair-pulling moments with this thing, special thanks to programmer Thomas Culhane not only with his coding skills but also his ability to keep me from the brink of insanity.
I'm going to forget some of the smaller issues we faced. Most of the problems centered around diagonal motion. It was not a fun time.
A huge thing with diagonal motion was the fact that the entity was unaware of its own size and shape. This forced it to scoot against walls and get stuck. Entities frequently got stuck in corners, as you see above.
Things are still not that easy.
Oh, silly you! You thought we fixed all of the problems! How presumptuous of you to assume that we "know what we're doing." Lol. We still face two major problems.
Entities have these things that I call "margins." Currently, the margin for all entities is 5 points. (1 tile = 48 points) The margin shrinks the entities' collision box down. Without it, passing through a 1 block space (as a player) would be astronomically difficult, because you have to hit the space just right - there is zero margin for error.
However, this presents our first problem. When the player scoots up against a wall, if his top-left point passes into the wall's borders, his position will register as wall. (Since the block an entity is in is determined by the top left corner of said entity) That means that the destination of the path in respect to the zombie becomes impassible. (since the player is, to the zombie, inside of a wall) This causes the pathfinding to stop operating and read as no possible paths to the destination.
Secondly, the entities just aren't smart enough. Let's say the zombie locks a path to the player, but the player starts moving left and right over and over again. This will force the zombie to repeatedly recalculate its path, and the zombie will be left a confused mess! (I can't seem to get a good video example of this right now, though if I do I'll be sure to post it!)
Anyways, that's what's going on over here in The Labyrinth! Until next time!