Showing posts with label Production. Show all posts
Showing posts with label Production. Show all posts

Monday, 15 April 2013

UnityWii Issues

I have tried vigorously to get some sort of wii mechanics working which would allow the user to steer their car via wii-mote however I have ran into a few issues trying to do it.

The main issue is that the wiiyourself library is in c# language and my car movement script in javascript. Obviously it is very difficult to use variables between different types of scripts and this has proved problematic. I have tried creating a javascript variable which allows me to add the script in to access these variables which initially worked out fine.

I would have preferred to do it the other way around by accessing the c# script in my javascript file however for some reason the new version of unity doesn't allow what it did in the previous versions and after roughly 30-45 minutes trying I simply could not access the c# variables in the javascript.

I then set a couple public float variables called pitch and roll in javascript which I would then use set in the update method equivalent to the pitch and roll values of the wii remote. However after adding a similar script as above I finally realized the variable values weren't updating so nothing was happening to the cars.

After having thought through every possible solution I could I looked online for help but was just given the same sort of solution that I have already implemented. I will write another blog shortly when or if I come up with a solution.

Thursday, 11 April 2013

Getting to grips with Unity Wii

Now that the deadline for this project is near I now need to add Wii controls to add more interactivity and user feedback to my game. I haven't had any past experience with this so far so this week I just decided to test out the kit I downloaded from  https://github.com/lonewolfwilliams/WiiYourselfUnity/blob/master/README.md and see what I can come up with.

The original demo included in the kit showed the user how to rotate an object based on the rotation dimensions of the wii-mote. Although this wasn't particular relevant to my game I was interested to see what could be achieved using it and decided to apply this code to see if it would work well with a maze game. 


The controls seem a bit off but that is mainly down to the positioning of the camera. This is a good example of a game which can have multiple levels of feedback because I could have set up multiple cameras and then gave the game the option to press a key to switch between cameras for better views of the maze.

I now tried out moving a cube in unity using the wii-mote which is much more appropriate for my game. I was able to get some basic movement done by translating the players position with the following line of code.

transform.Translate(pitchRoll.pitch * Time.deltaTime, 0f, 0f);

What this line of code does it moves the cube on the x axis dependent on the pitch value, angle of the wii-mote, and times it by the delta time which allows for a smooth movement. The other two values are the Y and Z axis which are set to zero.

I think that I can use code similar to this in my car game and update the position constantly so that the movement isn't limited . I can then add in the code used to rotate the maze above to turn the car. This would work similar to the keyboard keys because if the player turns anti-clockwise the number is a negative which reverses the cube and clockwise a positive which accelerates it. 

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. 



Thursday, 28 February 2013

Physics Issues

Car Physics:
The car physics did not go as planned. The car would flip over and rest upon its side if the car was to suddenly turn at high speeds. Now obviously this is no good as in a car game you would expect the car to travel at high speeds and have to navigate around many corners. Below is a video which shows you the issue I encountered.

As you can see from the video above the car goes spiraling out of control. It took a while to solve this problem before finding out the reason which is down to the rotation settings on the model.

The rotation settings on the car are not all set to a default value of zero which means the car isn't properly upright as it appears to be in the video. 

In fact, due to the rotation on the Z axis, the car is technically on its side which means because we added a rigid body. The rigid body applies gravity to the car meaning it only takes the smallest push before gravity played its part and flipped the car back to its side (zero on the x axis).

Too fix this issue I have to go back into Blender3D and change all the values back to zero. However a problem with the Blender to Unity exportation is that it changes the X rotation value to -90 on import.

This means in order to set it to zero I need to set the X rotation to -90 and then apply the rotation and then change it to zero again. This would solve the issue however as I created my model incorrectly on the Z rotation axis meaning the values I changed earlier get reset again meaning I can't change two axes this way without messing up the shape of my model.

The reason it would mess it up is because I created it in separate parts instead of two (mesh and wheels). If I want to use this mesh I would need to recreate in Blender3D making sure all the rotations are at zero first however given the time and effort it took to create it would take too long and have chosen to use a free-to-use model instead.


Friday, 4 January 2013

Car Movement

Creating a movable car
Theory:
Programming realistic car movement is much harder and advanced than anticipated. Controls I usually use to move an asset is based around transforming the assets position along an axis when a key is being pressed. This logic does not suit car movement because a car does not behave that way.

Cars move with increasing velocity depending on the amount of torque being generated from the driver by pressing the pedals. When a driver hits the breaks the car doesn't go to a dead stop immediately it does so over a short period of time due to car velocity and tire friction.

These factors all need to be considered in order to create a car game which simulates realistic movement as much as possible. I did not feel I could create a script from scratch given my minimal coding experience in Unity3D so I used a tutorial to help out.

Setting the stage:
Before creating and applying a script to the car asset, car mesh talked about in creating assets section, I needed to set up the car properly. When importing a model which includes greater than one mesh item, Unity3D automatically adds all the meshes as a child of an empty game object. I do not want this.

First I needed to un-child all the mesh items, make the car chassis the main parent and then delete the empty game object. I then need to rename all my objects, for future reference, to appropriate names such as FrontRightWheel, RearLeftWheel, Chassis etc. 

Now I needed to create an empty game object which will act as a container for the wheels. I dragged the four wheel into this container making it the parent and then attached it to the car. 

I then needed to duplicate the container, renamed each wheel, add a wheel collider and then remove the mesh as we don't need it. The wheel colliders will be used to ray-cast down at the ground which allows for constant collision detection with the floor.

I now need to add a rigidbody to the car chassis which simply adds gravity to the car and then two box colliders around the car mesh used to bottom and top collisions.

Creating the script:
Using the car tutorial from the Unity3D assets store, http://u3d.as/content/unity-technologies/car-tutorial/1qU, I was able to develop a script in the C# language. The script was developed using the front two tires to steer the car using torque.

The script translates the players position using the axes and the stored input keys "Vertical" and "Horizontal" which has the stored keys values in them.

The script also uses a set list of integers which is used to increase the amount of tire rotations depending on the speed the car is travelling at.

I also used a javaScript code which would handle tire movement which basically rotates the tires.

Thursday, 8 November 2012

Assets


Asset Design:
The first asset I needed to create was the vehicle which the player will be taking control of in the game. I began by looking through several car images which I could use to model my assets after and after much deliberation I decided upon creating a formula one styles car. I searched online for some blueprints and came upon one which was perfect. 

Blueprints:

The first thing I needed to do was to split this image into two using the GIMP2.0 software. The reason for this is because Blender3D allows for the user to have split screens so the user can work on the top view and side view of the model simultaneously.

Mesh Creation:
I don't wish to delve into too much detail when discussing the creation process as it can't get very long, technical and dull to read. Too create my model there were four simple steps which was creating the mesh, creating the UV texture, applying the texture and then exporting and importing the model from Blender to Unity.

Mesh:
The first thing I needed to do to my mesh was to add a plane in the top view, center in the middle of the blueprint, subdivide the surface and then delete half the cube. 

The reason for this is because the car chassis is exactly the same on the left as the right so instead of having to create both sides I can add a mirror modifier to the plane which then mirrors the left hand side of the model.

After roughly three weeks and around twelve hours of modelling I was able to create a mesh which looked something like the blueprints above. 


As you can see from the image above the car looks very plain and is not yet ready to be exported and used in Unity3D. I now need to add colour to the model. Usually I would just selected a part of the model and apply a material colour however Unity only supports UV texturing on imported models.

UV Texturing:
UV Texturing is simply applying a 1024x1024 png image onto the model in the Blender3D's UV Texturing view. First you need to break up the model in the UV editor view. I did this by selecting faces and unwrapping them in the UV editor.


Above is final UV map of the chassis. Blender3D allows for the easy exportation of UV maps by simply pressing the UV option and then export UV Layout. This image is now saved and I can access it within GIMP2.0 to start texturing it. My model will be relatively plain because I used the mirror modifier on the chassis meaning what ever I texture on one side will be mirrored on the other.

Due to this I am unable to attach unique images to the chassis because they would be mirror on the opposite site which will make text unreadable and images look wrong. I decided to use the colours red and and white.


I created my UV Image, as you can see above, which I added to the materials section of my Blender3D project and then added to the UV Layout. I repeated this for the other parts of my model i.e. Wheels and ended up with a satisfying result.


This model is now importable into Unity3D which I was able to do by exporting as an FBX file and then importing the file in the Unity3D project. FBX are imported at a scale of 0.01 which means the mesh is much smaller than expected. This was rectified by changing the scale factor on the FBX models properties panel and then applying it.