# Unity - How to calculate max distance (range) of a Projectile taking drag into account?

I am able to calculate the projectile max distance, but it only works when there is no drag applied on the spherical projectile. I used the formula for range of a projectile as follows:-

void OnCollisionExit(Collision other)
{
if(other.gameObject.name == "bat")
{
initVel = ballRigidbody.velocity.magnitude;
lineObject.transform.LookAt(transform);
angle = Mathf.Abs(lineObject.transform.eulerAngles.x - 360);
maxDistance = (initVel * initVel * Mathf.Sin (2 * radianAngle))/ g;
}
}


This works well if there is no drag. But as I add drag, the range ends up being far away from where the projectile actually lands.

but can't quite understand how to use it.

Here's a solution I tried

if(ballHeight > maxHeight)
{
maxHeight = ballHeight;
}
else
{
if(!flag)
{
maxHalfDistance = Vector3.Distance(ballFollow.transform.position, centerPoint.position);
maxDistance = maxHalfDistance * Mathf.Clamp(maxHalfDistance, 1f, 1.75f);
flag = true;
}
}


Basically calculating horizontal distance at max height and multiplying it a value between 1 and 1.75. ballFollow is horizontal position of ball and centerPoint is the launch position. This works perfectly but there is a problem that actual range isn't calculated until the ball reaches its maxHeight.

So, how can range of a projectile be calculated taking air resistance in account?

• Do you have any solution so far. i need help with that also. can you give me complete script? – K97 Jul 9 '18 at 11:32
• This webpage explains the formulas clearer than Wikipedia: grc.nasa.gov/www/k-12/airplane/flteqs.html – S. Tarık Çetin Jul 9 '18 at 13:50