Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Crawl navigation graph

So far the nav graph has only contained data for shooting from point to point. The AI crawling was basically fake. I wanted the nav graph to allow the AI to crawl intelligently.

I started by simply connecting points together within a certain radius. I had some bugs at first, but you can see what I was going for:

Next, I wanted to do some raycasts to ensure there were no obstacles between points before connecting them.

For co-planar or concave surfaces, a single straight-line raycast works fine. For convex surfaces where the AI bot needs to crawl around a corner, two raycasts are necessary. This image illustrates the case I was planning for:

Here the AI bot would be crawling horizontally around the triangular shape. It should be able to crawl around two of the corners, but the third corner is blocked by another piece of geometry.

When connecting two points on different surfaces, I ended up calculating the intersection line between the two surfaces, picking the closest point on that line, and doing two raycasts from that point to each of the two candidate connecting points.

Here's a screenshot of the results inside the triangular geometry. The points on the obstructed corner on the right are not connected.

Here's how it looks when it's all working.

Corner cases

The movement code works by placing the player a small distance away from the surface and raycasting toward that surface. I realized you could leak through the geometry by shooting and landing very close to a sharp angle like the one beneath this ramp:

Here, the attachment point could be flush with the floor while the player's position is actually inside the ramp.

I've been beveling and removing these problematic angles, but I realized the code needs to handle this case because it's possible for players to create arbitrary geometry by spawning force fields. The fix is thankfully pretty simple. I just do a few dot products and nudge the player away from the corner.

Crawl glitch

This issue has been looming since the beginning of the crawl code. It happens when you're on a corner and you try to move adjacent to both surfaces:

Here we're trying to move upward, but the movement vector gets clamped against the surface we're currently on. The code transitions you to the other surface, which then clamps your movement vector in the opposite direction. You end up jittering back and forth between the two surfaces. This can also happen with concave corners.

I solved this by preventing the player from transitioning to a new surface if the new clamped movement vector would send the player back toward the original surface. Now it just slides smoothly along the edge.

Sniper

Not much to say here. I added a sniper ability. It increases your range and allows you to attack without moving. Each bullet costs 10 energy, and your position is immediately revealed to the enemy after firing. It's particularly potent when combined with force fields.