How would I calculate this?

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

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.

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

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))

Thank you very much, worked flawlessly.

1 Like

Ok actually after some more testing I found that it’s facing the opposite direction as the fuel decreases

Example:

Are you sure your fuel doesn’t go below 0 or over 112?

Nope, that was when it was at 50 fuel.

Ok, somehow I got it to work like this.

local rotation = 56 - (-56 - 56) * ( 1 - (value / totalFuel))*2