# Doing less damage based on magnitude

Essentially my goal is to find the player’s magnitude, then deal damage based on it
If you’re further away, you take less damage
My best idea is to do something like 100/magnitude, but I’m not sure if that would work super well
Are there better ways?

1 Like

That would work well, make sure to get the magnitude of distance from the source of the damage to the player rather than the magnitude from `(0, 0, 0)`.

You might want to check out the Inverse-square Law (wikipedia.org) and see if that fits your intended effect better, though I’m sure using the magnitude should do the trick.

yeah i took it from the monster to the player so it should be fine i hope

That should be fine, you might want to tweak the damage reduction slightly though and probably use `math.clamp(value, min, max)` as well, since if `magnitude < 1` then the damage done would be more than the actual damage.

1 Like

well thats fine, the way i ended up doing it is i had a really big number so that way if youre pretty close you just die (its supposed to be op anyways so)

Alright, should be fine in that case. Don’t forget to mark this post as solved once you have received the answer you are looking for!