Answers for "Damage drop-off over distance on a physical projectile"
http://answers.unity.com/questions/1310378/damage-drop-off-over-distance-on-a-physical-projec.html
The latest answers for the question "Damage drop-off over distance on a physical projectile"Answer by alankemp
http://answers.unity.com/answers/1311445/view.html
You can use [Mathf.Lerp][1] to interpolate between two values. In this case, you want to lerp between your min and max damage by the amount you are in the drop off range.
float GetDamage(float bulletDistance, float minDamage, float maxDamage, float dropOffStart, float dropOffEnd)
{
// Use the min/max damage if we're outside the drop off range
if (bulletDistance <= dropOffStart) return maxDamage;
if (bulletDistance >= dropOffEnd) return minDamage;
// Where in the drop off range is the distance we are interested in?
// We want this in the range of 0 at the start to 1 at the end so we can use Lerp
float dropOffRange = dropOffEnd - dropOffStart;
float distanceNormalised = (bulletDistance - dropOffStart) / dropOffRange;
return Lerp(maxDamage, minDamage, distanceNormalised);
}
[1]: https://docs.unity3d.com/ScriptReference/Mathf.Lerp.htmlFri, 10 Feb 2017 14:05:38 GMTalankemp