Daybreak (3D Survival RPG)

In Summer of 2014, I began working on Daybreak, a 3D online survival RPG.  Here are some example of the work I've done so far. It's mostly been a learning experience for me to learn how 3D works and just how complex it can be. Here are some samples of code I've worked on for this project:


Terrain 

My terrain system uses what are called "chunks". Essentially, this means that instead of loading one gigantic 3D model for the terrain - the game engine will instead load smaller "chunks", if you will, as they are needed. This system is prevalent in a lot of games, for example Minecraft generates it's terrain on the fly using a similar chunk system.

To facilitate this process, I wrote a Blender script which splits the terrain into many chunks, names them accordingly, and exports each chunk into it's own separate .OBJ 3d model.

The game engine then finds the chunk with the correct name, closest to the camera position, and loads it in. Chunks way off in the distance are labeled as 'unloading' and after a certain amount of time, they are set to 'unloaded' and removed from the scene.

Using this technique, instead of instantaneously loading and unloading chunks, the terrain chunks will not pop in and out if the user moves back and forth. Instead, the game will wait a small amount of time. 

An image showing some of the source code for the Blender script:

The large terrain in Blender before, note the single object in the hierarchy:

After running the script, we can see that there are now many separate objects in the hierarchy view, named accordingly:



In the game engine

Now that we have all of our exported 'chunks' of terrain, we will move on to how the actual terrain engine works!

Here, you can see some of the source code in TerrainSystem.java.
You can see that there is a single void called 'generate' which adds all of the right chunks to their correct places.

TerrainPatch.java, where you can see that each TerrainPatch has it's own 'page state': Loaded, unloading, or unloaded.
You can also see in the update method, the timer which determines when chunks are removed from the scene.

The terrain engine in game, along with some grass and a sky, running very smoothly:







AI

Here are some examples of code for the AI in Daybreak. 

You can see below, that hostile NPC's do not immediately chase a player just because the player is nearby. I wrote a method to check weather the hostile NPC is facing the correct direction in order to actually see the player.
Showing how animations and move speed is updated according to weather the NPC is chasing the player, waiting, or wandering. For this NPC, they became more aggressive at nighttime.