Mostly internals hacking this week. I started working on support for placing nodes in levels, so that I can define paths for objects like moving platforms to follow, and build graphs for the player AI to use for pathfinding.

Linking an object like a moving platform or a monster to the pathing data is an interesting challenge. The list of objects in the level and the graph that represents the pathing data are both in entirely separate objects, with no straightforward way to acquire references to each other. To complicate this further, there’s no way to guarantee that all the pathing nodes an object depends on will have been loaded before the object. This basically means that I need to go to some sort of two-stage initialization model, which is a bit of a pain.

One of the problems that this causes is that the algorithm I use to partition a level’s geometry becomes fairly useless, since it depends on knowing the boundaries of a given piece of geometry. If a moving platform is attached to a series of 8 different pathing nodes, the only way to compute the possible boundaries of the platform is to walk all eight nodes and compute a rectangle that contains all of them – probably large enough to be utterly useless for optimizing collision detection. Doors have a similar problem, but due to the fact that they move on a fixed axis it’s less problematic. This probably indicates that I need to move to a model where an object’s bounds can change on the fly as it moves, and will require some significant changes to my object model.

I also still need to come up with a good strategy for attaching metadata to the pathing nodes. Some nodes need to have information attached directly – for example, a given node might be attached to a door, so the game needs to know that the node might not be traversable depending on whether or not the door is closed. However, some data needs to be attached to the connections between nodes – for example, if I have one node on the ground and another node up in the air, the connection between those two nodes needs to indicate that the player gets from one node to the other by jumping.

If I attached that data to the nodes directly, then I would end up with a situation where the only way to move from a given node is by jumping, even if it’s possible to walk onto it from one direction, jump onto it from another, and fall onto it from above. This does still have some ambiguity issues regardless, though, since if you can get to a node by jumping onto it, the reverse action (going backwards) just involves falling, not jumping. In this case I need some way to represent connections where the action you take depends on the direction you’re going.

Tags: , , ,