How to deal more damage the closer something is?

I’m making a gun script right now and I have 2 values, 1 called “MaxDamage” which is the max damage it can deal when the person hit is right up close and 1 called “MinDamage” which is the min damage it can deal when the person hit is at the farthest range of the bullet.

How would I make it so that the player hit gets dealt more damage the closer they are to the person who shot them and less the farther away?

1 Like

Check out Magnitude in the wiki:

I already use that, but what is the formula to make it deal MORE damage the CLOSER it is.

Current % code to find how how close it was to its max range.

((hitPoint-script.Parent.Position).magnitude)/stats.Range.Value

if distance <= 20 damage = 100
elseif distance <= 50 damage = 80
elseif distance <= 70 damage = 50
end

Something like that?

Or range / magnitude = damage

BaseDamage * (maxDistance - Magnitude) If there’s a limit to how far you go

3 Likes

Thats what I was looking for, thanks! :smiley:

1 Like