Tuesday, April 29, 2014

The Basic Game in Unity 3D


My First Simple Car

Developed in Unity 3D

My first Simple Car
   I make a simple car which is I watch in the tutorial from (youtube.com) and i study all the components of Unity 3D. I choose 3D not 2D, because for me 3D is easy than 2D but it depends to you. anyway, my first simple car can move around. It can move forward and backwards. Also it can turn left and right.
    So first, lets find out how to make a simple car.

Lets Create: New Project!

First, you have to click New Project 
Second, after clicking New Project, you have to only to click create because its just a basic. Anyway, you can rename it by deleting only the New Unity Project 3  to your what you like sample C:\Users\SERVER\Documents\My First Simple Car. You don't need to import packages because as what i have said its just a basic. Then Setup defaults for 3D of course because you have to create a 3D simple Car and that is the time to click Create.
and wait for a while... 
and this is the time that you have to create a 3D Simple car, but first you need to have some basic need for creating this game, you need Cube that can be found in: Red arrow Game Object then Green Arrow Create Other lastly Blue arrow Cube.
 

 Lets Create: Ground for our Game!

Then you have created a 3D Cube
Then make this first as your ground
Change the Scale: X=20 Y=1 Z=20. And to identify that this is ground you have to rename it from Inspector Panel

Then Rename, type Ground. this is how to Rename the Cube and other Game Object to Identify it from Hierarchy Panel.

 Lets Create: Simple Car!

As what we have create a simple cube. Its just same. Same process Create Game Object > Create Others > Cube

NOTE!: if you create a cube then it can be seen, you have to move your cube upwards using green arrow or set you Position Y=1. Then it will instantly raised.

 Then change the Transformation Properties Scale  Y=0.5 Z=2



Shortcut Keys to Remember :
    F - Default view
    Alt + left click + drag - viewing the object
    Ctrl + D - Duplicate object
After creating a cube, you have to duplicate it (CTRL + D) and drag it up then Change the Transformation Properties Scale Y=0.5 Z=1
Then for Wheel of our Simple car. Click from Game Object >  Create Other > Cylinder. 
Note: Make sure that you set your Position from the Inspector Panel > Transformation Properties of your cylinder to X=0 Y=1 Z=0 to make it center from your Simple car or Like this picture showing. to make an exact Position for your Wheel later.

Don't worry, we have to fix it by changing the Transformation Properties of  Rotation X=0 Y=0 Z=90.
Its to big enough. so lets fix the Transformation Properties of Scale of the cylinder to X=0.5 Y=0.7 Z=0.5.
Petty good. then we have to Duplicate the Wheel. By pressing the Shortcut Key: Ctrl + D and Drag it by clicking the Blue arrow backwards just like in the picture below, and you can customize it. Whatever you like.


Nice! that's it... but one thing that we have to fix.
IMPORTANT!: You have to Create Empty from Game Object Shortcut Key: Ctrl + Shift + N. 
Because all objects created from a Simple Car. Like all of this showing in the picture below
All objects except the CarAll, Ground and Main Camera are Highlighted or I mean Selected then you have to drag those selected to CarAll.

just like this picture below
 and that is the simple steps in making Simple Car. But

 Lets Try To Run!: Simple Car

Important: To run this simple car. You have to click like this button or Play Button.

 And this is the Result:


Our camera or Main Camera cannot capture of our simple car because it’s Dark! So we have to add a Directional Light from Game Object.
  Important: When adding a Game Object, Make sure you have to stop the running of the game. All you have to do is Click again the Play Button.

 Lets Create!: Directional Light


To do that you have to go in Menu Bar> Game Object > Create Other > Directional Light.
This is the directional light with the icon Sun like. But is seems to dark from our Simple Car. So we have to Set up first our Directional Light away from our Simple Car. All you have to do is Change the Transformation Properties of the Position X=0 Y=5 Z=0 and the Rotation X=50 Y=100 Z=90.



Or you can make it little darker so that you can add a Spotlight.

 Lets Create!: Spotlight

To make a Spotlight for our Simple Car Click Menu bar > Game Object > Create Other > Spotlight.
After adding Spotlight then set up the transformation of Position X=0.25 Y=1 Z=-0.4 Rotation X=0 Y=0 Z=0.


Then you have to Duplicate it by pressing the Shortcut Key (Ctrl + D). Then Just Set up the Position X=1 of the Transformation Properties of the Spotlight. Make Sure that you selected the Duplicate Spotlight before you setup its properties.

After adding the Directional Light and Spotlights.

 Lets Try To Run!: Simple Car

Important: To run this simple car. You have to click Play Button.

We can see now the Simple Car because of the Directional Light. But the Main Camera is not set up properly to our Simple Car so That we have to Align to our object which is our Simple Car.

  Important: Make sure you have to stop the running of the game. All you have to do is Click again the Play Button.

 Lets Set-up!: Main Camera

Make Sure that you have selected the Main Camera from Hierarchy.
 After selecting the Main Camera, you have to Set-up now the Transform Properties from Inspector Panel. Position X=0.5 Y=3 Z=-2 Rotation X=35 Y=0 Z=0.

 Lets Try To Run!: Simple Car with Main Camera

And that is the Previewing of our Simple Car. You can Adjust the Transform Properties of your Main Camera whatever you like. Like Farther from your Simple Car or Closer from your Simple Car as what have you see in the picture above and many more. As on me I use Closer as a Basic for you to see the Simple Car or our Game Object and the Ground and also the Spotlight.

 Lets Design!: Color the Simple Car


This is Colored Simple Car. And this is very easy to do this.
First Click Assets from Menu Bar > Create > Material .


Then a New Material will add in your Assets

Then Click the Main Color Highlighted with Red from Inspector.
 After that if you see the pop - up Color Panel that is the time that you have to select Color for your material.

 i Click Green because this is for my Ground. After clicking a Desired Color. All you have to do is to click the X to close the Color Panel.
So lets apply it to the Ground. Just simply Drag and Drop the New Material Colored with Green to the Ground.

And That's it! Great we have create a Color to our Ground.
How about to our Simple Car? Sure! same process. Create a New material. Click Assets from Menu Bar > Create > Material . Then Change the Color to Blue. and Click and Drag then Drop to Simple Car.
 Also for the Wheels of the Simple Car.

Put a Scripts for your simple car

Movements - (Forward and Backwards)

void update()
    { 
if (input.Getkey(keyCode.W))
    {
   transform.position += transform.forward * 5.0f * Time.deltaTime;
    }


   if (input.Getket(keyCode.S))
    {
         transform.position -= transform.forward * 2.0f * Time.deltaTime;
      }
   }

 if (input.Getket(keyCode.A))
    {
         transform.rotate (0.0f, -80.0f * Time.deltaTime, 0.0f);  
   }

 if (input.Getket(keyCode.D))
    {
         transform.rotate (0.0f, 80.0f * Time.deltaTime, 0.0f);  
   }







No comments:

Post a Comment