Search Unity

Better way to script AddForces in 2 axis

Discussion in 'Scripting' started by rodrigozol, Oct 21, 2011.

  1. rodrigozol

    rodrigozol

    Joined:
    Apr 4, 2009
    Posts:
    29
    How is the better way to write this script to apply 2 forces on Axis. As I'm not a programmer I wrote 1 line for each force. Tks

    Code (csharp):
    1. function Update () {
    2.  
    3.  if (Input.GetKeyDown ("space")) {
    4.  
    5.         var tempBullet1 : Rigidbody;
    6.  
    7.         tempBullet1 = Instantiate(bullet1, transform.position, transform.rotation);
    8.         tempBullet1.rigidbody.AddForce (Vector3.forward * 2000);
    9.         tempBullet1.rigidbody.AddForce (Vector3.up * 500);
    10.  
    11.     }
    12.  
    13. }