Thursday, December 4, 2014

65 days - learning how to do FPS games using unity

Okay, so today I will learn how to make a FPS(first person shooting) games using unity

So the first thing is to find tutorial, I searched youtube but figure out the video is too long, 25 minute one episode and up to 10 episode, so it is around 250 minute or 5 hours of content

So I search for the shorter version of the tutorial and I found a tutorial on below link

http://noobtuts.com/unity/first-person-shooter-game

the tutorial gave the C# code, but I only want javascript, so i modify the code in javascript as below

rocket.js
var explosionPrefab : Transform;

function OnCollisionEnter(collision : Collision
{
    // Rotate the object so that the y-axis faces along the normal of the surface
    var contact : ContactPoint = collision.contacts[0];
    var rot : Quaternion = Quaternion.FromToRotation(Vector3.upcontact.normal);
    var pos : Vector3 = contact.point;
    
    Instantiate(explosionPrefabposrot);
    // Destroy the projectile
    Destroy (gameObject);
}



shoot.js
var Bullet : Transform;
 
 function Update ()
 {
     if(Input.GetButtonDown("Fire1"))
     {
         var newBullet=Instantiate(Bullet,transform.position,Quaternion.identity);
 
         newBullet.rigidbody.AddForce(transform.forward * 1000); 
     } 


}

No comments:

Post a Comment