Enxqi
(Enxquity)
December 20, 2020, 10:42pm
#1
So my total capacity is 112 and I want to calculate the correct distance between two points.
Point 1 = 56
Point 2 = -56
Point needed to calculate = something between 112 and 0
So I want 112 to be 56 and 0 to be -56 and I want to calculate the points between it if you know what I mean.
What are you even asking? This makes 0 sense to me.
1 Like
Enxqi
(Enxquity)
December 20, 2020, 10:45pm
#4
Ok I don’t think im explaining this right, I have a fuel gauge and the max fuel in the vehicle is 112.
The min rotation is 56 and the max is -56.
I want to calculate where the rotation would be depending on the fuel.
pilotjc
(BlameLuau)
December 20, 2020, 10:46pm
#6
ur predefined variables, 56-current fuel level
Are these literal points in 2D space or are you trying to perform mathematical operations on 2 numbers?
Edit: Nevermind, just saw your 2nd reply.
Just divide your current capacity by your total capacity and then multiply between your minimum value and your maximum value:
local TotalFuel = 112
local currentFuel = 50
local rotation = 56 + (-56 - 56) * (currentFuel / totalFuel)
This is called interpolation: Basically what is being done here is we are calculating what percent of the total fuel is filled, from that we add what percentage of the difference (difference between the start and goal) to the start - this gives us the rotation.
3 Likes
Enxqi
(Enxquity)
December 20, 2020, 10:49pm
#9
Ok that somewhat worked but the needle is on the inversed side of where I want it.
Subtract the (currentFuel / totalFuel) from 1:
(1 - (currentFuel / TotalFuel))
Enxqi
(Enxquity)
December 20, 2020, 10:51pm
#11
Thank you very much, worked flawlessly.
1 Like
Enxqi
(Enxquity)
December 20, 2020, 10:59pm
#12
Ok actually after some more testing I found that it’s facing the opposite direction as the fuel decreases
Example:
Redridge
(Red)
December 20, 2020, 11:09pm
#13
Are you sure your fuel doesn’t go below 0 or over 112?
Enxqi
(Enxquity)
December 20, 2020, 11:10pm
#14
Nope, that was when it was at 50 fuel.
Enxqi
(Enxquity)
December 20, 2020, 11:33pm
#15
Ok, somehow I got it to work like this.
local rotation = 56 - (-56 - 56) * ( 1 - (value / totalFuel))*2