Showing posts with label unity 3d car game tutorial. Show all posts
Showing posts with label unity 3d car game tutorial. Show all posts

Saturday, 1 June 2013

Unity3d Car Game Tutorial-9 (Creating a Split Screen Multiplayer Game)

It is Vacation time and I want to complete this tutorial series as soon as I can so that we can start with a new series, if possible.
In this post we will be learning how to make a split screen multiplayer (2 players to be precise) racing game where in one user controls a particular car using the keys 'W A S D' and the other user controls another car using 'I J K L'.
So what are we waiting for, 3.....2.......1........ RACE

Step 1: Duplicate the 'Car' transform by right clicking and selecting 'duplicate' option ('ctrl+d' can be used as well)


Step 2: Rename it to say, 'Car1'. Reposition this Car1 as in the image below


Step 3: Go to GameObject --> Create Other --> Camera and create a new camera











And then you should get something like this on your 'Hierarchy' section.















Step 4: Attach the 'CarCamera' script to this new camera as well. And set the 'target' to 'Car1'.













Step 5: Now we will create a javascript for this 'Car1' and name it as 'Car1' itself. Now copy the 'Car' script and paste it into this 'Car1' script.
To make the 2nd car controlled using the keys ' I J K L', find the code below in the 'Car1' script:

function GetInput()
{
throttle=Input.GetAxis("Vertical");
steer =Input.GetAxis("Horizontal");
if(throttle < 0.0)
brakeLights.SetFloat("_Intensity", Mathf.Abs(throttle));
else
brakeLights.SetFloat("_Intensity", 0.0);
CheckHandbrake();
}

Now Change the 'Vertical' to 'Vertical1' and 'Horizontal' to 'Horizontal1' and save the script. As a result you should have something like this:

function GetInput()
{
throttle=Input.GetAxis("Vertical1");
steer =Input.GetAxis("Horizontal1");
if(throttle < 0.0)
brakeLights.SetFloat("_Intensity", Mathf.Abs(throttle));
else
brakeLights.SetFloat("_Intensity", 0.0);
CheckHandbrake();
}

Finally to finish this step, replace the 'Car' script on 'Car1' with this newly created 'Car1' script and fill the blank variables in the inspector section, if any, as per requirements.


Step 6: You will come across this error, if you have done the steps correctly, which says:
 "Assets/Scripts/JavaScripts/Car1.js(64,7): BCE0132: The namespace '' already contains a definition for 'Wheel'."

Now go to the 'Car1' script and 'comment' the lines of code of 'class Wheel' and you should get something like this:

/*class Wheel
{
var collider : WheelCollider;
var wheelGraphic : Transform;
var tireGraphic : Transform;
var driveWheel : boolean = false;
var steerWheel : boolean = false;
var lastSkidmark : int = -1;
var lastEmitPosition : Vector3 = Vector3.zero;
var lastEmitTime : float = Time.time;
var wheelVelo : Vector3 = Vector3.zero;
var groundSpeed : Vector3 = Vector3.zero;
}*/

Than save it to see the error being vanished.


Step 7: Now we will add the keys to control the 'Car1'.
For this, go to Edit --> Project Settings --> Input and you will see the 'Input Manager' on the 'Inspector' section. Expand the 'axes' and  do the changes as in the image below (DO the changes for the 'Horizontal' and 'Vertical' after the 'window shake y'):





















Step 8: Finally we will split the screen into two halves. To do this you need to change the 'Normalized view port rect' of both the cameras.
For the 'Main Camera' apply the values as shown in the image below:













And for the 'Camera' apply the values as in the image below:













This is it. We have a split screen two player racing game. Race with your friend and have fun.

+1 it and Share it if you found this useful. And circle me, if you still have not. Also leave your comments behind.

Thursday, 30 May 2013

Unity3d Car Game Tutorial-8 (Adding AI Cars)

Due to some reason I cannot continue making videos on Unity Car Game Tutorial Series, however I will be writing posts on it instead, hope you will appreciate the posts as you did for the videos. So let's kick off then.

In this bit of the tutorial we will be adding AI Cars to our game. Follow the steps below carefully and you shall be successful in adding AI cars and make the race game more enjoyable.
(Try to use a track which is flat and does not include up's and down's, like in the unity3d demo project)

Step 1: Drag the Car transform from the 'Project' section into the 'Hierarchy' section and name it as (say)           'AICar' (Search for 'car' in the 'search' bar in 'project' section)

Step 2: Create a Javascript named AICar_Script and add the code from the link here

Step 3: Replace the 'Car' script of the 'AICar' with the AICar_Script script

Step 4: Now create WheelColliders for the rest 3 wheels as well, as we had did it earlier for the Front Wheel (Simply duplicate WHeelFL by clicking on it once and pressing 'ctrl+d' and rename them as 'WheelFR', 'WheelRL', 'WheelRR') and synchronize them with the 3 wheels (the two images below should help in clearing doubts, if any).















Step 5:  Now drag the wheels and the wheelcolliders onto the hierarchy as in the image below





Step 6: Go to GameObject and create an empty Gameobject and rename it as 'WaypointContainer'

Step 7: Go to GameObject -> Create Other -> Sphere and create a sphere, and move it onto the WaypointContainer gameobject, and place the sphere on the terrain as if it is just kissing the surface, this is our first waypoint.

Step 8: Create waypoints like this all along the way, so that your AI car follows the waypoints (more the waypoints, better the result.) The Images below might help in clearing this point (The spheres or the small dots you see in the image on the right are the waypoints)












Step 9: Now drag this WaypointContainer onto the Waypoint Container of the AICar_Script as shown in the image below





















Step 10: Set the Gear Ratio to the values shown in the image above.

This is it, if you have followed this post correctly then you should have an AICar in your race game.
You can follow the same steps to create more AICars.

Hopefully this post is clear and hope this helped you, comment if you have any issues.

Saturday, 18 May 2013

Game Creation Tutorial - Special Episode: Unity3d Car Game (Interfacing Kinect to Unity)

In this bit of the tutorial, we will learn how to interface the Kinect camera to the Unity car racing game.


Refer to the video below for more details.






The kinect folder used here can be downloaded from the link below:
Kinect  or Kinect
                                                           







This is it for the Part-8 of this tutorial series. We'll learn more in the following posts.
Comment if you have any queries.


Saturday, 4 May 2013

Unity3d Car Game Tutorial-7 (CREATING LAP AND CHECKPOINT SYSTEM)

In this bit of the tutorial, we will add Laps and Checkpoints system to our car racing game.


Refer to the videos below for more details.






The scripts used can be downloaded below:
Checkpoints
CarCheckpoint
Timer


This is it for the Part-7 of this tutorial series. We'll learn more in the following posts.
Comment if you have any queries.


Friday, 19 April 2013

Unity3d Car Game Tutorial-6 (Saving Best Time using PlayerPrefs)

In this bit of the tutorial, we will learn how to use the PlayerPrefs to save the Best Time taken to complete the race and also save the Name of the player who completed the race in the respective time and display it on the screen.

Refer to the video below for more details.






The timer script used here can be downloaded from the link below:
Timer


This is it for the Part-6 of this tutorial series. We'll learn more in the following posts.
Comment if you have any queries.

Wednesday, 17 April 2013

Unity3d Car Game Tutorial-5 (Speed Indicator)

In this bit of the tutorial, we will learn how to add a SPEED INDICATOR to the game screen.

Refer to the video below for more details.







This is it for the Part-5 of this tutorial. We'll learn more in the following posts.
Comment if you have any queries.

Thursday, 11 April 2013

Unity3d Car Game Tutorial-4 (Stop the car after it reaches finish line)

In this bit of the tutorial, I will show you how to stop the car once it has crossed the Finish Line.


Refer to the video below for more details.

Car Game Creation Tutorial using Unity3d-4... by gluedbrain





This is it for the Part-4 of this tutorial. We'll learn more in the following posts.
Comment if you have any queries.



Unity3d Car Game Tutorial-3 (Finish Line)

In this bit of the tutorial, I will show you how to make a Finish Line to our race and stop the timer once the car has reached the finish line.

Refer to the video below for more details.

Car Game Creation Tutorial using Unity3d-3... by gluedbrain





You can find the code used in the above video below.
Timer


This is it for the Part-3 of this tutorial. We'll learn more in the following posts.
Comment if you have any queries.

Unity3d Car Game Tutorial-2 (Timer)

In this bit of the tutorial, I will show you how to setup a Timer to keep track of the time past.

Refer to the video below for more details.


Car Game Creation Tutorial using Unity3d-2 TIMER by gluedbrain


You can find the code used in the above video below.
Timer
Countdown


This is it for the Part-2 of this tutorial. We'll learn more in the following posts.
Comment if you have any queries.


Unity3d Car Game Tutorial-1 (Countdown)


Hello unity users, I'm starting a new car game tutorial for you all. I'll use the car game demo from the asset store as our reference instead of building it from the scratch.

So lets get it started then.

In this bit of the tutorial, I will show you how to set a countdown, so as to give a racing game feel.

Refer to the video below for more details:

Car Game Creation Tutorial using Unity3d-1... by gluedbrain



You can find the code used in the above video below:
countdown
This is it for the Part-1 of the tutorial series. We'll learn more in the following posts.
Comment if you have any queries.