nmdist-log

Decals and Pathfinding

This week I had some time to squeeze in some work on two different things: decals and path finding.

Pathfinding

In GoldSrc, map authors place down info_node entities which the engine will build a graph out of. NPCs will then use that graph to navigate the level. At some point I’d like to make my own levels for my engine, so I wanted to avoid extra manual steps to get pathfinding working. I stumbled across the Recast and Detour navigation libraries. I’ve been staying away from dependencies, but these libraries don’t have external dependencies (not even the STL!) and just require a C++98 compliant compiler. Luckily there are a few crates that wrap these libraries for Rust, so I didn’t have to do that on my own. Although I have forked them to make some changes.

At first, I wrote a small program to create a navigation mesh for the level c1a0 and then create a path for a scientist that walks to the desk in the lobby at the beginning of the game. The program spit out the control points into a text file that the nmdist engine can read at runtime and visualize: A path plotted in c1a0, starting at a scientist and going down the hall into the lobby.

After that I brought the navigation mesh building into the engine itself, as well as adding a mode to visualize the navigation mesh: A view of the navigation mesh built for c1a0.

And finally, I pulled in the straight path computation from the RecastDemo project from the original library. You can now run a console command and the engine will plot and visualize the path between two entities. A straighter path plotted in c1a0, starting at a scientist and going down the hall into the lobby.

In the future I need to hook up NPCs to follow the computed paths, as well as hook up their animations to their movement actions. I’d also like to tweak the path generation, I’ve never liked how much the path finding algorithms tend to “hug” the wall.

Decals

The other thing I worked on was decals, particularly for bullet holes and blood splatter. First, I played around with techniques to project a texture onto some given geometry: Three meshes that depict a wall corner, with a debug texture projected onto them.

As you can tell, there’s some stability/coherency issues with the method that I’m using. But after staring at Half-Life for awhile, it’s not perfect between faces there either. I’ve decided to declare victory for now, and I can always revisit it in the future.

After that I started to build a system to place a cube on surfaces that get shot, and clip the surrounding geometry to that volume. However, I can’t get the geometry clipping to work quite yet… A wall in c1a0 that has its vertices showing as well as a clipping cube visualization.

And that’s it for this week!