I’m pretty close to releasing Demo 2, I’ve implemented the last features – now it’s just a matter of fixing a few bugs. This post has a movie showing various features at the end.

Properly spawning and walking NPCs

I’ve had exterior NPCs in before but they didn’t move or spawn properly – sometimes they’d come in at invalid spots. I decided to try raycasting to determine if a spot was valid but there were multiple problems with that. There would be a lot of raycasts and collision checks every frame as NPCs were added, removed and move. In addition, the raycasts would determine a spawn to be valid but it really isn’t, it’d be in a bad area or too close to a building. To fix that would require multiple raycasts to cover an area or other more costly solution. Instead, I gave up on the raycast / collision idea and picked a simpler solution. When a block is loaded, each vertex on its ground plane (16×16) is considered a valid spawn point. Then right after load (this is done only once) every building is checked – any spawn points inside it’s bounding box is considered invalid. Each row of 16 points is stored in a bitfield – so there is an array of 16 of these bitfields, one per row. So now a grid is generated around the player, where each vertex on the grid is a valid spawn point or not. When spawning a new NPC, it randomly picks a valid spawn point that is outside the field of view and within a certain range of the player. The beautiful thing about this system is that the NPCs use the same grid for movement. The NPC randomly picks a destination valid grid point from the 8 vertex region around its current point and that is used as a target point for the NPC to move towards. Once it reaches the new grid point it then selects another one and moves towards that. Full movement without any collision detection – except for guards when they are chasing the player, which act like enemies (these will not be in the demo). Finally when an NPC is outside a certain range and not in the player’s field of view, it is recycled – it respawns at a closer valid point and changes NPC skin.

Here you can see some screenshots of the NPC grid, green points are valid spawn points, whereas red points are outside of range or invalid.





I implemented the first pass of the climbing ability, although it’s a little fickle still. Anyway when the player collides with the world, if the “final” slide plane (i.e. the plane of the collision polygon(s) relative to the player velocity) causes the player to stop moving on the first collision iteration is purely vertical (i.e. the “up” component of the normal is 0.0) then the player can potentially climb that surface. Once the game decides that the player can climb, decided based on skill eventually – there is no skill check yet, then gravity is disabled and the player moves upward when pushing into the wall. As soon as the player stops moving forward or moves past the vertical surface, climbing mode ends and regular gravity is activated. It still needs some work but you’ll see climbing in action in the movie.

Sky Fogging

The fog color now matches the sky color, as you’ll see in the movie. This is done by rendering the sky background into a relatively low resolution texture. The vertex shader projects the object’s vertex position and generates texture coordinates into that texture. The color from that position is then used as the fog color, so objects will appear to “fade into the sky” no matter where they are.

There have been other miscellaneous tasks completed and issues fixed, but these are the major items.

The Movie

In the movie below, the player starts in a small town roughly South of Daggerfall. The player runs through the woods and you’ll notice that the walls of Daggerfall (and a few tall houses) are visible the whole time even though it takes about a minute and a half to run there. Various interiors are shown as well as NPCs walking around. You’ll also notice the smooth sky transitions as the time of day changes. There are some bugs and I accidently bring up the inventory in part of the movie, but it’s coming along.

High Resolution Movie