About Me

I started this website to document my exploits in a number of hobbies and perhaps the odd work related project. I like to help others, so when I have had to figure something out, be it CAD related, Software development, taking the car to bits etc. I will post it here so others can benefit.

I am not just going to write about everything I do, why reinvent the wheel? Just the things that I have trouble finding solutions to on the web.

I consider myself an expert with Autodesk Inventor. I spent some time as a tutor and have taught a number of people over the years. At some point I will reformat my tutorials for publishing on the web. 

I never intended to get into CAD, but I have an interest in figuring out how things work, rather than just how to use them. This lead to me being pretty good with Inventor and able to create some quite intricate and intelligent models. I am an engineer for Musk Engineering, who provide services to the process industry.

In my spare time I have taken an interest in software development, although it is fair to say I have no professional experience here. Mostly I have been tinkering with games development, just because I find it interesting. You will find details on this website. I am also the developer of Regatta in a Box. Regatta in a box is linked to my other hobby. I am Captain of Trent Rowing Club and have been there regularly since the year 2000. I spend around 15-20 hours a week involved with rowing, except on the couple of weeks I have off. to be perfectly honest it is surprising I find time for other hobbies.

Unity RTS Tutorial Part 3 - Terrain

Problems Adding Terrain

I need to add terrain here because in the next part I will be adding a mini map. One of the elements of that part is to add a lower quality copy of the terrain to the mini map rather than the main terrain so that a fully detailed terrain isn't being rendered twice.

Unity Terrain ComonentI thought adding terrain should be no problem here. I have done it before as part of another tutorial, although I cannot say I am experienced. I added a new terrain game object and tried to use the tools to "paint" my terrain. Nothing happened. After a bit of persistent attempts I turned to Google. It turns out there has been a bug in Unity for a while and the terrain tools do not work if you have changed the editor layout as I have. Apparently setting the layout to default fixes the issue. It didn't work for me so it may not have been a problem. I later found out that my problem was the "Opacity". If this is set to 0 no terrain will appear as you click on the terrain in the scene view. I went through a few terrain tutorials and some of the Unity manual on Terrain and at no point did I come across anything saying the "Opacity" needed to be adjusted before beginning. It is also worth mentioning that when you get to painting textures that the "Target Strength" may also default to 0 and needs to be above 0 for the tool to work.

Adding the Terrain

Finally we get on to actually adding the terrain. There are plenty of good tutorials on adding terrain so I won't be going into any detail about how to use the tools here. I just want to add a terrain to work with and show how it is integrated into our game. You can experiment with making adjustments to your own whenever you want.

In the Map scene we need to add a new terrain game object. It is found under the 3D object menu. Unity adds the game object to your scene and create a new terrain map file in your asset foler. I renamed mine "Map" and moved it into the scenes folder. I renamed my terrain object in the Scene to be "Ground". I then set my terrain to match the size of my current Ground Object. For me it has a transform position of x-550,y0,z-500. If you select the terrain game object you will see the menu above. The button on the right opens the terrain setting and will allow you to alter the length and width. mine are both currently set to 1000. You can then use the terrain paint tools to create a landscape. I also used the smoothing tool to make my terrain a hilly, but not mountainous landscape.

With this done you can remove the previous ground game object and remove or rename its prefab. Create a prefab of the new terrain object and replace the previous ground in the "GameObjectList". I am  not 100% sure the terrain will need to be a prefab or in GameObjectList, but with the code as it is at the moment it is required. If you run the game now your units should walk on the terrain.

Building on Top of Terrain

If you gave the terrain a good test you will notice that the buildings still get build at y=0. In many cases that even means that the building is placed below the surface of the terrain. To fix this we need to update the "FindBuildingLocation()" method in "Player.cs". This method gets the position the mouse is clicked when hovering over the terrain with the temporary building. The Following line needs to be removed or commented out;

        newLocation.y = 0;

Your game should now run and allow the buildings to be created on top of terrain. You will notice that if you build the building on a slop that there is empty space under the building on the downhill side of it. I plan to add foundations to my buildings when I add more buildings and units later, but for the moment I will live with it. Please see link below to the project on GitHub.

https://github.com/brotherkennyh/Unity-RTS-Tutorial-Development

Subscribe to