hello,
i am developing like link text game in unity2d. i want to create the same effect of generating path(white circles). and make
the bullet follow the same path. I have searched about this implementation and found that it is possible using projectile.
I referred link text but didn’t find any formula to generate path. can anybody help me how to implement this?
I already replied to this question. You can see [here][1]. How ever I’m posting here also for your convenience.
Vector3 [] GetTrajectoryPoints(Vector3 pStartPosition , Vector3 pVelocity )
{
float velocity = Mathf.Sqrt((pVelocity.x * pVelocity.x) + (pVelocity.y * pVelocity.y));
float angle = Mathf.Rad2Deg*(Mathf.Atan2(pVelocity.y , pVelocity.x));
float fTime = 0;
Vector3 [] pos = new Vector3[20];
int iNumberOfPoints = 10;
fTime += 0.1f;
for (int i = 0 ; i < iNumberOfPoints ; i++)
{
float x = velocity * fTime * Mathf.Cos(angle * Mathf.Deg2Rad);
float y = velocity * fTime * Mathf.Sin(angle * Mathf.Deg2Rad) - (Physics2D.gravity.magnitude * fTime * fTime / 2.0f);
pos *= new Vector3(pStartPosition.x + x , pStartPosition.y + y ,0);*
fTime += 0.1f;
}
return pos;
}
Here you need to pass start position of projectile and initial velocity and method will return the number of points on the projectile trajectory.
[1]: Trajectory of a projectile formula: get the same angles - Unity Answers