I’m making a custom explosion and it’s supposed to deal more damage the closer you are to the explosion point but for me it does the opposite, it deals more damage the further away you are from it. How can I make it work as intended, here’s my code:
local RADIUS = 50 -- damage distance from explosion point
local DEFAULT_DAMAGE = 30 -- max damage it can reach
local distanceBetween = (character.Position - rayResult.Position).Magnitude
if distanceBetween < RADIUS then
local damageDone = DEFAULT_DAMAGE * distanceBetween / RADIUS -- the damage calculation which doesn't work properly
end
I looked on devforum for similar issues and none of the solutions helped me
Oh nevermind, I see the issue with your calculation. Let’s say you were 5 studs away: 30 * 5 / 50 = 3 damage
Now if you were 10 studs away: 30 * 10 / 50 = 6. Your math is wrong.