Entity:GetVelocity

Hello.
I want to convert the Entity:GetVelocity to KM/h, and i wanted to know how would i be able to convert it?
Whats the value of it, is it meters?
Thank you.

Source units are based on inches, so you just convert using inches as the baseline.

I see, so it’ll be inches per second?

1 unit = 0.75 inches = 19.05mm https://developer.valvesoftware.com/wiki/Dimensions#Speed
From km -> mm = *10^6
From hours -> seconds = *( 60 *60 )
Complete = 1 unit/s = 19.05mm (6060hrs/10^6km)
[lua]local kph = math.Round( LocalPlayer():GetVelocity():Length2D() *19.05 *( 60 *60 ) /10^6 )[/lua]
Alternatively, to cut down on some processing time, 1 unit/s = 0.06858km/h, so you could just do this
[lua]local kph = math.Round( LocalPlayer():GetVelocity():Length() *0.06858[/lua]

I’m working on a huge unit conversion table, but for now I use these:


//
// Conversions - Josh 'Acecool' Moser
//
// 1 unit 									= 0.75 inches. 
// 4/3 units 								= 1 inch - from this we base our calculations.
CONVERSION_UNITS_TO_INCHES 					= 4 / 3; // 4/3 units per 1 inch, 16 units per foot
CONVERSION_UNITS_TO_FEET 					= CONVERSION_UNITS_TO_INCHES * 12; // 				== 16 in game units

CONVERSION_UNITS_TO_METERS 					= 0.0254 / CONVERSION_UNITS_TO_INCHES;
UNITS_PER_METER 							= 39.3701 * CONVERSION_UNITS_TO_INCHES;
-- print( 9.81 * CONVERSION_UNITS_TO_METERS, 9.81 * UNITS_PER_METER );

// Crap choices...
CONVERSION_UNITS_TO_METERS 					= CONVERSION_UNITS_TO_FEET * 0.3048; -- 1 foot = 0.3048 meters. 16 units = 1 foot...
CONVERSION_UNITS_TO_MILES 					= CONVERSION_UNITS_TO_FEET * 5280;
CONVERSION_UNITS_TO_KILOMETERS 				= CONVERSION_UNITS_TO_FEET * 3280.84;
CONVERSION_UNITS_TO_MPH						= CONVERSION_UNITS_TO_INCHES * 17.6;
CONVERSION_UNITS_TO_KPH						= CONVERSION_UNITS_TO_INCHES * 10.936133;

CONVERSION_UNITS_KM_TO_MILE 				= 0.62137119223733387264;
CONVERSION_UNITS_MILE_TO_KM 				= 1.609344;


I would recommend never hard-coding numbers into code. If you go back later and look at code, it may be confusing as to what each multiplier or divisor means… Use CONSTs ( typically all uppercase in other languages, values that aren’t meant to change after the initial assignment )… That way you can look at the code and say, oh this is converting velocity to MPH or KPH / KMH:

vehicle:GetVelocity( ):Length( ) / CONVERSION_UNITS_TO_MPH
or
vehicle:GetVelocity( ):Length( ) / CONVERSION_UNITS_TO_KPH

CONVERSION_UNITS_FOR_GMOD_FROM_SOURCE_ENGINE_SHIT_I_ALREADY_FORGOT_THE_VARIABLE_NAME
// Copyright © Trademark ® Ollie ‘Little preb fag’ ‘Leeroy’ Jenkins 2012-2014
// All rights reserved, do not use without a written permission


(User was banned for this post ("Please don't pick on users/shit posting" - NiandraLades))

If it’s only used in one place you could just add a comment explaining what it is.