Thursday, 21 March 2013

Creating a Mini Map

This week I decided that since I was developing a car game a mini map would almost be an essential element for this. Creating a mini map was much simpler than it sounds. The first thing which I needed to do was to add a new camera to the scene and place it high above the terrain and position it so it is level with the car. 

Once I position the camera I then needed to change the camera view from perspective to orthographic. Orthographic view simply squashes the map into two-dimensional form and gets rid of the depth of the map which is visible in perspective view.

I now needed to change the depth value of the camera to 1 and the main game camera to 0. 0 is issued to the camera which you want to be used as the main camera and then other cameras in the screen are numbered correspondingly. 

Now I needed to go the game window and re-size the scale of the camera's view and position it in the bottom left hand corner of the screen. This is done simply by messing around with the X, Y, Height and Width values until I was happy.

This would be fine however I do not need to add such a high detailed mini map. All I want is to display the terrain, road and agents in the level and the agents them selves are very small to see. 

To solve this I needed to duplicate my terrain and then set all the detail values to the lowest possible which makes the map less resolution and deletes the trees in the terrain.

I now need to get rid of the first terrain, meshes and cars and can achieve that by tagging them as the terrain layer. I then go into the mini map cameras properties and make sure it doesn't show objects with layer tag 'Terrain' which is done simply buy un-checking Terrain in the culling mask and vice-versa for the main camera.

Now because I made the cars apart of the terrain layer they aren't visible in the mini map now. This will not do. To represent the cars I will use plains which I will place above the cars and colour code them the same as the cars. I will add them to the mini-map layer making them only visible in the mini-map camera and then child them to their retrospective cars.

Doing all this I was able to achieve a fairly good mini map however this isn't the most professional approach to creating one but it works fine and I am happy with it. Below is a picture showing you what the map looks like.


Thursday, 7 March 2013

Car AI

Having not updated my blog in a while I felt it was time to do just that so here I am. Now with the car physics sorted out I now needed to add in some sort of competition to make the game much harder. 

I done this by adding another car to the level which will have the same scripts as the players car (Car_Move which moves the car on key press and Wheel_Alignment which rotates the wheels depending on speed) except I need to make a few moderation to the  car_move script.

First, however, I need to add in way-points which are simply set points on the map where you want the car to follow. Way-points are a cheap and easily way to make a car look like it is using AI to make decisions on its own however all it will do is check which way-point it needs to steer towards to and then approach it in a straight line.

Obviously since I have a race track which has many corners and curves I will need way-points at a regular interval to give the illusion the car is turning around the corners.

I create the way points by first creating an empty game object and naming it way-point container and set all its values to zero. I then duplicate that, renames it waypoint0 and then place it just in front of the start line of my track. 

I do this regularly and change the name each time to increasing numbers until I have plotted the entire course and then place all the way-points as a child of the container. I now need to amend the code where it checks for key presses and remove that adding in code that simple checks if the player has arrived at the desired way-point and if it hasn't steers the car towards it.


The way-points are represented using spheres on the picture above. I had to use 112 way-points in the end.
I had help creating this script from the car tutorial mentioned in an earlier blog. This worked fine except a few issues occur when the player either collides with the car and it struggles to move towards the way-point or sometime ever steers in reverse to the next way-point.

The car also sometimes travels to a corner too fast and goes off the track. Although there are a few drawbacks to this technique I is good to use until I am able to create a path finding script which would work more efficiently. 

Below is a clip showing the enemy car navigating around the track using way-points.