Coding a projectile to travel through multiple vector

I am in the process of creating a realistic single player shooting app.

The app already generates an array in order to determine the elevation and distance the projectile will travel. For instance:

Start position - will be at mytransform.
1st location - 50 units forward of start position, 100 units up of start position.
2nd location - 100 units forward of start position , 150 units up of start position.
3rd location - 150 units forward of start position , 200 units up of start position.

//then coming down

4th location - 200 units forward of start position , 150 units up of start position.
5th location - 250 units forward of start position , 100 units up of start position.
6th location - 300 units forward of start position, 50 units up of start position.
End position - Impact

And so on and so forth.

If someone could point me in the right direction with some vector math code in order to get me started I would be grateful.

why are you storing positions in an array in order to work with projectile trajectories? seems like an odd approach.

Are these start positions?
Or are you trying to describe projectile movement through these points in array?

The positions are created by a complex system in order to generate a perfect ballistic profile. It may seem like an odd approach, however, I can assure you for what I am trying to do, it is really the only approach.

When the player clicks ‘fire’ a two dimensional array is generated that holds everything from the time a “real” bullet would take to travel from position to position, the elevation of the bullet in relation to the bore height, the remaining energy the bullet has at each point, distance traveled, etc…

Bear in mind that this ballistic profile is gnat’s ass accurate. All that is left is the vector math that will allow the bullet to travel from point to point.

There is only one start position. I am trying to describe the parabolic arc of a bullet. All that is left is the vector math which should just be a loop the array from point to point, which is what I am trying to accomplish.

You might want to check out Vector3.MoveTowards This allows and object to move from point a to point b in a straight line.

What you want to do with it, is write a method (possibly a co-routine) that checks whether the bullet’s current position is approximately the position of the current point in the array and when it is, move to the next point, if it isn’t, keep moving.

Thank you for the reply. I will look into Vector3.MoveTowards. However, what I really need is for the projectile to travel from point to point depening on the units in my original post.

Are the vectors you save in the array world coordinates, or the distances to the next point? If the first, then you can use those values with the idea I presented, and if the second you can just calculate the world coordinates by taking your transforms world coordinate and increment it with the values from your array to get the word coordinates so you can use them for the idea…

Does the bullet have rigid body & physics interactions or are you trying to manually create the natural arc of the bullet ignoring its mass, gravity etc by plotting the curve as if the player is always holding the gun level when firing & the bullet always travels the same distance? Will you need to introduce things like friction/drag, wind effects, different profiled bullets & calibre?

Sounds like you want a spline or a beizer curve.

You can cheat and get some of this functionality for free by adding your points to an animation curve and reading the points off at various time intervals.

Or if you points are close enough you could just move the transform directly with Transform.position.

They are distances. My array holds the distance forward, the height or distance up and the distance left/right depending on wind and other effects on projectiles.

So right now for initial testing purposes I have this:

//note that all of my data are stored as type double…

    void CreateVectorArray (int x)
    {
       //So the intent here is to create an vector3 array which holds all the location data for the bullet on its way to the target. 

        Vector3[] positions = new Vector3[x];

        positions[0] = this.gameObject.transform.position;

        for(int i = 0; i < 5; i++)
        {
            positions[i+1].x = positions[i].x * (float)ptr[0,i];//this array holds the distance forward
            positions[i+1].y = positions[i].y *(float)ptr[9,i];//this array holds the distance up
            positions[i+1].z = positions[i].z *(float)ptr[4,i];//this location holds the distance left and right
        }
        for(int j =0; j < 4; j++)
        {
            Debug.DrawLine(positions[j], positions[j+1], Color.red);
            Debug.Log ("position[]" + positions[0]);

        }
      
    }
[\code]