Making a Game in Unity 014: Terrain Generation

Just so you know, this is not a tutorial series! I am writing this series mainly to give you a behind the scenes look at the process of making a game in Unity, and to document the development of this project.

See other posts in this series.

Making a game in Unity 014


Today was another busy day, but that should be the last one for a little while now. I’m really looking forward to making some decent headway this week!


This afternoon I started by finishing up the ladder functionality. I added support for multiple people being on the same ladder simultaneously, I made sure climbing up and down works properly, and I attached a ladder to the actual ship. I also made sure players couldn’t keep climbing past the top of the ladder into free space.

Aside from adding the ladders to the ship’s model, all that’s left is to sort out the dismounting process when a player reaches the top of the ladder. Currently, players are simply released, which in most cases means falling all the way back down. That’s obviously not ideal.

I also took some time to fix the stairs. Walking up steps works great now, although it’s still a little “jumpy” (it’s difficult to describe what exactly is going on), but I’m not sure if there’s anything I can do about that.


This morning I fixed player behavior while interacting with things. Previously, whenever a player started interacting with a cannon or the steering wheel, he wasn’t constrained to a certain position, and so his body could end up moving to the other side of the ship while still being able to use the object. Now the player is constrained to a certain point and this doesn’t happen anymore.

Later on, I made a few modifications to the terrain generation algorithm I was playing around with last week. It now produces more island-like terrain, but it’s still only client side.


I started today by fixing a problem with players’ rotation being synced improperly, which sometimes led to the camera jerking in a completely different direction from where you were looking.

Next, I set up the mesh colliders for the terrain. This was a bit of a process in itself, so at first I just left it completely flat. Later in the afternoon though, I added the necessary code to make the collider match the client side terrain, meaning land can now be walked on! This required setting up a method to generate Perlin Noise since I don’t have access to Unity’s function on the server.

This evening, I started working on a little terrain generation mapper project with the goal being to make it easier for me to scout out nice looking terrain to use at the spawn area. At first, I tried doing this by programmatically creating a texture and setting each pixel’s color appropriate for its “height”. Unfortunately, this process took about twenty seconds every time, and Unity would essentially freeze for that duration. On top of that, every time I wanted to change a value in the formula, that process had to be repeated.

Since I wasn’t willing to wait that long to see updates in the terrain reflected on the map, I decided to move my code to the GPU. Strangely enough, the formula I use to get the height at any certain point doesn’t seem to be working in the shader, but I’ll have to fix that tomorrow.


This morning I continued working on the terrain mapperr. Eventually, I realized that initializing variables within shaders doesn’t work the way I thought it did—the compiler seemed to be ignoring the values I provided and was just initializing everything to zero. Once I fixed that, it started working properly, and instead of taking forever to update, changes in the formula are now reflected instantly!

Screenshot of the mapper with nice island terrain generation
This method of displaying the terrain generation in shaders could potentially be useful for in-game maps as well.

Next, I made the whole thing easier to use, and I added a sea level parameter to the formula, which I also added to the actual game’s code later in the evening.


Yesterday was a pretty busy day, so I don’t have any updates. Today was pretty similar, although I found the time to start writing a terrain shader. At this point it simply tints the ground green above a certain Y level to imitate grass.

What’s next?

Next week I’ll finish up the terrain and add rocks and foliage to make the world more interesting. I’d also like to get started on player-water interaction (flotation, swimming, underwater visibility, etc).

See other posts in this series.