Basically, what i want is to get a number depending on the magnitude from the impact center to the HumanoidRootPart
Example:
If the magnitude of the player = 100, the damage will be 1, magnitude=50 => damage=50, magnitude=1 => damage=100
Basically, what i want is to get a number depending on the magnitude from the impact center to the HumanoidRootPart
Example:
If the magnitude of the player = 100, the damage will be 1, magnitude=50 => damage=50, magnitude=1 => damage=100
You can do that by, Getting the Impact point’s Vector3 cords and player’s character’s Vector3 cords, then Subtracting Impact point Vector3 from Player’s character’s Vector3 will get a relative vector coordinates to the impact point. Then use the Magnitude property of the result vector and do if-else statement by the following:
if(resultVector.Magnitude == 100) then
damage = 1
elseif(resultVector.Magnitude = 50) then
damage = 50
elseif(resultVector.Magnitude == 1) then
damage = 100
end
But how do I get damage depending on the magnitude if the Magnitude ~= 1, 50, 100?
Any formula or function?
How do you want to get the damage? Like percentage drop or what?
You can use a negative linear function that is clamped.
So y = -mx + b
Its also in the documentation with a code example
-- look for a humanoid
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / explosion.BlastRadius -- get the distance as a value between 0 and 1
distanceFactor = 1 - distanceFactor -- flip the amount, so that lower == closer == more damage
humanoid:TakeDamage(maxDamage * distanceFactor) -- TakeDamage to respect ForceFields
end
This roblox example is similar to @LakshyaK2011 idea except its in decimal percentage form 0-1 and not 0-100%
I assume that you want to damage player but as the magnitude increases the damage decreases.
You can just do that by:
Defining the damage radius in studs values. Then
if the player is in radius then do:
get the percentage of how much player is away from impact point’s magnitude,
then subtract the percentage from 100, and then get the total number of damage points by that calculated percent of players total hp
Imagine that i put it into a ability system, that doesn’t uses an explosion, but creates a part after the condition has been meeted(on the animation keyframe), then how do i get the damage?
The magnitude is counted from the created part
Thats actually a genius idea, dont know why i didnt do that earlier
Thank you!
No problem man, that’s what makes me feel good and happy!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.