My weapon script has a damage falloff so the further you are the less it does. I’m just looking how to make a graph or curve like an audio source has for 3D sound. Can anybody help?
I would recommend using an AnimationCurve. You could use it to do something like:
// DamageFalloffCurve is a public AnimationCurve
// MaxRange is a public float
RaycastHit hit;
if (Physics.Raycast(/* Bullet raycast params */) {
float damage = DamageFalloffCurve.Evaluate (hit.distance / MaxRange);
// Do damage stuff ...
}
Just be sure your raycast’s MaxDistance
parameter is passed MaxRange
or you may get unwanted values.