# How to make an Object follow a projectile motion pathway

Beginner Here. I was watching a tutorial on how to make a pathway projection using line renderer. And it worked. I can input a initial velocity and a angle and it renders the path it would follow. But now I want to have an object follow this pathway. How would I go on about this?

Pathway Projection Code

``````void RenderArc()
{
lr.positionCount = resolution + 1;
lr.SetPositions(CalculateArcArray());
}

//calculates the points needed to the arc
Vector3[] CalculateArcArray()
{
Vector3[] arcArray = new Vector3[resolution + 1];

float maxDistance = (velocity * velocity * Mathf.Sin(2 * radianAngle)) / gravity;

for(int i = 0; i <= resolution; i++)
{
float t = (float)i / (float)resolution; //ensures all points are equally spaced
arcArray *= CalculateArcPoint(t, maxDistance);*
``````

}

return arcArray;

}

//calculate height and distance of each vertex
Vector3 CalculateArcPoint(float t, float maxDistance)
{
float x = t * maxDistance;
float y = x * Mathf.Tan(radianAngle) - ((gravity * x * x) / (2 * velocity * velocity * Mathf.Cos(radianAngle) * Mathf.Cos(radianAngle)));
return new Vector3(x, y);
}

Good day.

IF you know all the points (vertex) of the line redered, you only need to make the object go to the 1 by 1.

You can use the function Lerp to smooth the movement.

something like this:

object.transform.position = Vector3.Lerp(object.transform.position, NextVertex.transform.position, 0.2f)

(Take not i’m using t parameter as 0.2 to do a very very samooth movement, but of course you can try to increase it up to 1)

Bye!

I found an amazing tutorial regarding the trajectory projectile motion. this might help you a lot.