How to calculate everything in between in math?

I’m just curious, but how would I be able to calculate points in math, without them actually being there?

What I’m talking about, is, let’s take this example.

local num = 0
local magnitude

while wait() do

magnitude = (workspace.Wedge.Position - workspace.Part.Position).magnitude

if magnitude =< 20 then
     num = 10
end

if magnitude >= 100 then
     num = 100
end

end

With the above code, you can see that num is 10 when magnitude is or is less than 20, and num is 100 when magnitude is or is greater than 100.

Now what I want to know is how can I calculate what num would be when magnitude is, let’s say, 60, without actually setting what it would be at that value in the script.

Thanks in advance (if you answer).

By the way, I’m sort of not curious, because I want a damage range system in my guns, so that’s basically it.

  1. remember it is always >= or <= equal to ALWAYS proceeds the less than or greater than.

  2. Magnitude is a fancy way of saying the distance between two nodes. You are on the right track

So how would this work with the example I gave?

So I completely misread the question in my first response, so what you’d actually want to do is what is called a peacewise function where there are multiple parts.

You’re peacewise would look something like this

local function DamageRange(Range)
	if Range <= 20 then
		return 10;
	elseif Range >= 100 then
		return 100;
	else
		return 1.125 * Range + -12.5
	end
end
1 Like

I’m sorry if I’m asking too much but would 1.125 and -12.5 change depending on the value set by Range, and if so, what mathematical equation would I compute to set the right value?

The mathematical equation that you are looking for is:

range_percent = (Range - range_min) / (range_max - range_min)
num = num_min + (num_max - num_min) * range_percent 

range_min, range_max, num_min and num_max must be defined by you. In your case:

  • num_min = 10
  • num_max = 100
  • range_min = 20 (the min magnitude)
  • range_max = 100 (the max magnitude)

As an example let’s assume Range = 60. Then:

  • range_percent = (60 - 20)/(100 - 20) = 40/80 = .5
  • num = 10 + (100 - 10) * .5 = 10 + 90 * .5 = 55

So num = 55 for Range = 60.