So I am making a car system and I want to display speed in SPH, MPH and KPH. Are they correct? if not how can I fix my formulas for them? I am pretty sure that one of my formulas is wrong, so I need some help.
-- x variable contains Part.Velocity.Magnitude
local function toSPH(x)
return x -- I am not sure what to do here, I tried multiplying by 3600, but thats not correct. I am missing something
end
local function toMPH(x)
return (x / 1609.344 / 3.571 * 3600) -- is this correct?
end
local function toKPH(x)
return x * (20000 / 3600) -- is this correct too?
end
A Part’s velocity is studs per second, so for studs per hour yes you would multiply by 3600.
local function toSPH(x)
--[[
studs 3600 seconds studs
------- * ------------ = -----
seconds 1 hour hour
]]
return x * 3600
end
For the others it depends on the coefficient you use to convert studs to miles or kilometers.
local function toMPH(x)
--[[
let M be the conversion factor of studs per mile
studs 3600 seconds 1 mile miles
------- * ------------ * ------- = -----
seconds 1 hour M studs hour
]]
return x * 3600 / M
-- OR do this:
return toSPH(x) / M
end
Then converting to km/hour is easier:
local function toKPH(x)
return toMPH(x) * 1.609
end
local function toSPH(x)
return x * 3600
end
local function toMPH(x)
-- return (x / 1609.344 / 3.571 * 3600)
return toSPH(x) / 3600
end
local function toKPH(x)
--return x * (20000 / 3600)
return toMPH(x) * 1.609
end
Alright so I did this. I used MPH and I multiplied by 1.609, as suggested by Google. However I think i did MPH wrong. Because in first one I multiply it by 3600 and then I divide it back by 3600.
It appears to be: m = x/1609.344/3.571*3600, as the formula.
local function toSPH(x)
return x * 3600
end
local function toMPH(x)
return (x / 1609.344 / 3.571 * 3600)
-- return toSPH(x) / 3600
end
local function toKPH(x)
-- return x * (20000 / 3600)
return toMPH(x) * 1.609
end
70 studs per second = 252000 studs per hour
70 studs per second = 43 miles per hour
70 studs per second = 70 kilometers per hour
Now that we have a conversion of studs to a real-life length unit we should use that and then convert kilometers to miles instead of the other way around.
local function toSPH(x)
-- (x studs / second) * (3600 seconds / 1 hour) = (studs / second)
return x * 3600
end
local function toKPH(x)
-- (toSPH(x) studs / hour) * (1 m / 20 studs) * (1 km / 1000 m) = (km / hour)
return toSPH(x) / 20000
end
local function toMPH(x)
-- (toKPH(x) km / hour) * (0.6213 miles / 1 km) = (mi / hour)
return toKPH(x) * .6213
end
My orginal formula for mph works. Although it might give higher numbers than you want, cause 1 stud being 20 meters would mean that 1 stud is pretty massive. You might want to play around with what you represent 1 stud to be, unless you just want it to be perfect.
I just explained this to you. It is all relative to to what you represent 1 stud to be. Maybe you want 1 stud to be 2 meters, instead of 20. I just picked 20 cause it was on the wiki
So 0.28 meters is 0.0001739839 miles.
That gives me 1 stud is equal to 0.0001739839 miles.
Does this mean that formula will be (studs * 3600) * 0.0001739839?