Procedural Hex World

Some early stages of procedural generation in Hex world. I’m using Manhattan distance with voronoi to define biome borders. At the moment I have fields, deserts, and swamps in the world being generated with different terrain. This is still early stages, but an interesting test. The recording software im using is still a piece of crap, so expect stuttering.

Ultimately the procedural gen is looking cool, but is bogged down by that whole entropy thing that follows it like a curse, 100 million ways to make the same bloody thing.

Advertisements

New World Manager

Some progress on the new world manager for Hex World. Allowing me to dynamically load in world chunks to allow for the support of significantly larger levels. Hopefully this can be done in time for the imagine cup world finals. The recording software is twitchy as all hell and slow as shit, so it is all better than it appears, still not where it needs to be though. Refactor, rework, refactor etc etc.

Here is a video of the chunk loader set to load a tile per frame, slowing it down and visualising what it is doing. In the above video the chunk loader was set to create half a chunks tiles per frame. This whole thing may need some threading at some point, but getting threading to work with unity requires a certain level of self hatred to put your self through that hell. In other words expect that soon.

Image below of a 128 x 128 chunk world (16384 total chunks) in reference to the player and his total loaded space,which is a 4 x 5 chunk space. So yeah, way more space.

128 x 128

Hex World World Shifting

I’ve needed to create some better systems to manage world shifting in the game. And have managed to do so with a system that buries all the back ground code made to communicate with the world manager in an abstract world shifter class object.

Here is a video showing 3 kinds of world shifters I have made with this system. The first is a sphere shifter, second a volume shifter,  and the third is a pulse shifter.

Hex World New Tiles

I’ve gotten a little tired of how uniform the whole world looks with these perfect tiles. I want to create a tile system that will better reflect the environment you are in. If you are in a grassy field then you should not be getting tiles that are perfect in shape, but a little jagged.  But if you are inside of a house you may want perfectly shaped tiles.

So I need to create a procedural system that can create tiles as jagged as I want them for a scene, while still keeping all the tiles perfectly interlocked. In order for me to do this I shift each vertex within a certain sized circle based on how jagged I want the hexagon. Then make sure that any other hexagons who share vertex positions apply the exact same offset.

hextile offsetting

The application of this new procedural approach worked really well, letting me have complete control over how the tiles are formed and creating a nicer aesthetic for more natural environments. Below are some tile generations at no offset, some offset, and max offset.

Hex World First Demo

Have been working hard on Hex World these past few weeks and have finally gotten the world manager system created that can handle the dynamic nature of the world, a variety of tiles that have unique behaviour, and some simple tools that has helped me create a simple level to test everything out in.

screenshot_Mon_May_30_00.20.02

The video below shows how the world manager can maintain different tile stack compositions and handle the recreation of tiles, the grouping of tiles to move as one, and a bunch of different world tiles with different behaviour. There are grass tiles that sink in when stood on and be destroyed, pressure switch tiles that can be activated, mine tiles that can blow up when stood on or wired up to a pressure switch tile, and jump pad tiles that can launch the player up as well as some others.

AirShip, AI and Physics

I was having some fun with 3DS Max and created an air ship. I’ve been spending the past weeks getting it flying in the Unreal engine, and getting some basic AI to see if I can get it to navigate in 3D space.

I used to play a lot of Garry’s mod when I was younger. Whenever you wanted to make something fly you would give it hover balls to lift it at certain points. This whole thing reminded me a lot of the buoyancy spheres I used when creating my ocean, except in reverse. So I created a hover ball game objects that would split the weight of the object among them and then apply equal force to get them the object to float perfectly on the spot. This was way more successful than I original thought it would be and I was even able to split the distribution of force among them to create a sort of procedural animation. I also stuck some fans onto the airship that would speed up or slow down depending on the amount of force being applied to its respective hover ball.

I also had to sort out some AI for the cannons on the side of the airship. This was harder than I thought it would be, but proved an interesting math puzzle. In the end I got it to aim perfectly at the target regardless of the turrets orientation.

Lastly I got some AI onto the airship to get it to follow patrol points, attack the player, or flee. The end result was really cool, as the airship would instinctively perform a 3 point turn to turn around. This was because instead of having the AI move the ship, it moves a virtual joystick that moves the ship. Creating a more natural and less clunky movement system. The video below shows me setting up a patrol route and letting the airship navigate it.

 

Ocean Optimisation

It has been fun programming this ocean, and I want to optimise its use. What I  want to use is a method projecting a flat plane from the camera and its frustum onto the ocean, and then use this plane to create my ocean. This would mean that in terms of the mesh i use for the ocean I will be making use of all of its vertices. A really cool method that was also mentioned in the article about the tech behind assassins creeds oceans that inspired me to start this (Assassins Creed Tech Article).

In the image below you can see what i have to do to get this method to work, not only to i have to project onto this invisible plane, but have to account for what to do if the projection does not hit the plane. So all i have to do is reflect the vector off the roof and fire it back down, some fun little math to get this working.

Accidentally left my music on during the video posted below, so enjoy the Persona 3 sound track.

projection of plane

I even managed to take this further by using a really cool site called Desmos to form some equations to force vertices to cluster around the point of focus on the ocean, making even more efficient use of the vertices, meaning i no longer have half of them rendering parts of the mesh being projected onto the horizon. Below you can see the equations on the site and the effect of the clustering.

 

screenshot_Wed_May_25_17.03.49screenshot_Wed_May_25_17.12.50

 

Buoyancy

I wanted to implement buoyancy in order to get object floating on my ocean. The way I implemented this was through buoyancy spheres. This is what was used in Assassins creed to implement buoyancy in an efficient and accurate manner. Multiple buoyancy spheres are attached to objects in order to provide an approximation of the objects shape. Below I have attached some buoyancy spheres onto a cube. I can then check the height of the ocean at each point of each sphere and determine how much of it is submerged to determine the amount of upwards force.

I factoring in 3 forces into these physics, gravity, buoyancy, and drag. I was having a few issues initially with reaching an equilibrium that would have the objects settle and float normally on the ocean. In the video below you can a real propulsion of objects out of the water.

I added some debug arrows to my buoyancy spheres to represent how much of each force was being applied to each one. This helped me find where the issue was in my math and find the point of equilibrium in my buoyancy. The green arrows is the force of gravity, blue is buoyancy, and yellow is drag, and purple is the overall force.

Capture

In the end I got some good results, I was really happy with the approach of buoyancy spheres. They provide great results with a low cost and a flexible application.

Ocean Simulation

I love games which can change the entire mechanics of its self by creating a world that is something different. This is what the Mario Galaxy games did by creating planetary bodies to open up a variety of new mechanics that otherwise would not have been available. And this is also something Assassins Creed Black Flag did with its ocean, creating a non-static world that was something I had never experienced before. It was a world with a personality, that could work with or against you.

Ever since I played the game I wanted to figure out how there ocean worked and create it. Lucky for me I came across an article that interviews an Ubisoft employee who explains how the ocean works entirely (Assassins Creed Tech Article).

One of the first thing I wanted to get right before anything else was getting the waves procedurally animating on a plane. With a series of values that I could adjust to change the size, speed, or shape of waves. Before I could do any of this I had to study into Gerstner waves. A Gerstner wave is a wave that forms peaks and troughs. And the collective Gerstner waves is a summation of multiple individual Gerstner waves of different amplitudes and wave lengths to form a fractal implementation.

I decided to work with the Unreal Engine, because I enjoy working with its Blueprint system for creating shaders. The implementation of Gerstner waves into a shader also went rather well with the use of this GPU gems chapter of water simulation (GPU Gems Water simulation Article). Helpful laying out all the equations I need to implement this functionality. Though I came across an annoying issue that I have never seen before. For some reason Unreal Engine shaders do not use radians or degrees. Instead they use a normalised value between 0 and 1. So 2pi (Radians) = 360 (degrees) = 1 (Unreal). I do not understand why it does this, but it took a long time to debug.

I managed to get the shader set up, and a manager that could send down values to the shader in order to control the shape, speed, or size of the waves being created. The end result was very effective, and am quite happy with this first step.

 

Looping World Terrain

Was messing around with Unity to create a looping world. Bit of a difficult thing without just using dead land and teleporting the player unknowingly to the other side of the world. What I got set up is a series of terrain cells that stitch together and store objects locally, meaning objects move locally to there cell and not the world. They then trade object references with one another whenever they try to cross borders and change the objects local reference. Below is a video where you can see all of this working, including the player jumping around in the object hierarchy on the right and the world shifting to keep the cell with the player in the centre. The effect was pretty cool, and a fun experimentation with Unity’s terrain system.