Search Unity

Bullets is flying only on x axis

Discussion in 'Scripting' started by cinco, Aug 30, 2015.

  1. cinco

    cinco

    Joined:
    Apr 11, 2013
    Posts:
    11
    Hello all, currently I have an instantiatyed bullet that is created as such:

    Code (csharp):
    1.  
    2. GameObject bullet = (GameObject)Instantiate (Bullets, point, NormalCamera.gameObject.transform.rotation );
    3. bullet.transform.forward = NormalCamera.transform.forward;
    4.  
    This issue is that when I instantiate the bullet the bullet is firing at correct angle/direction.
    However, I store a bunch of data in a Vector Array that alters the flight of the bullet.The vector array takes control of the bullet immediately (which is what I want) What math would I use to ensure that bullet continues to fly in its instantiated direction but updates with my vector array data? Currently the bullet only flys on the x axis?

    Code (csharp):
    1.  
    2. void CreateVectorArray (int x)
    3.     {
    4.         positions = new Vector3[x];
    5.  
    6.         positions[0] = this.gameObject.transform.position;
    7.  
    8.         for(int i = 1; i < x-1; i++)
    9.         {
    10.             positions[i].x = positions[i-1].x + (float)ptr[0,i] - (float)ptr[0,i-1];//yards
    11.             positions[i].y = positions[i-1].y + ((float)ptr[10,i] + (float)ptr[10,i-1])*0.0277778f;//inches
    12.             positions[i].z = positions[i-1].z + ((float)ptr[ 4,i] + (float)ptr[ 4,i-1])*0.0277778f;//inches
    13.  
    14.         }
    15. }
    16.  
     
  2. cinco

    cinco

    Joined:
    Apr 11, 2013
    Posts:
    11
    Crickets?