Is my math correct for SPH, MPH and KPH?

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
1 Like

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
3 Likes

Velocity is in terms of studs per second.
1 stud is 20 meters.

1 meter per second is 2.237 miles per hour ( look it up or do the conversion math yourself if you dont believe me ).

Therefore to get mph you simply do
x * 20 * 2.237

For the sph multiply x by 60 twice.

Finally for kph, try it yourself, look up the conversion factor and just apply that knowledge

1 Like
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.

2 Likes

It depends on how many studs you want to consider to be part of a mile. That number would be multiplied by the result of SPH(x).

So according to this post.

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

1 Like

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

This is the right one. The units are all correct.

1 Like

Now it gives me 7 miles per hour for 70 studs per second and 12 kilometers per hour for 70 studs per second.

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 will try your formula for miles per hour then.

How come that 1 stud per second is 44 miles per hour.

local function toMPH(x)
	return x * 20 * 2.237
end
print(toMPH(1))
44.74
1 Like

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 according to Roblox Fandom Wiki. One stud is 0.28 meters.

Then use 0.28, no one is stoping you. Its your game in the end of the day, make it what you believe best represents it.

1 Like

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?

Well there you go. Just play around with that number and find something you like. Try 1 stud being 2 meters.

1 Like

And one stud is 0.00028 kilometers, given that 0.28 meters is 0.00028 kilometers.

And by the way, despite having a decent understanding of imperial measures, I’m more used to metric measures instead.