Speedometer is not accurate
So these lines of codes should show me the current meters per second of my player, but the actual float just doesnt seem right. What I mean is that, when idle, the value is something random such as: 1.376649e-05 not 0? And when walking the value also changes constantly.
The code that im using that every post seems to recommend
var vel: Vector3 = rb.velocity;
vel.y = 0;
mph = vel.magnitude * 2.237;
That's normal. The system is adding gravity, friction, and such, so velocity is always changing slightly. You can look up what 1.2345e-6 means.
What's 2.237? Unity velocity is already in meters/second (unless your game has 1 unit = 0.4 meters?)
To be honest, I'm not sure. But is there a solution to get a more accuarte value, or a more understandable value? I'd want to use it as a factor for weapon accuracy but with these values it wouldnt work.
Answer by Cynikal · Sep 09, 2016 at 10:17 PM
Change your var to int. That'll display a more whole number (0, 1, 2, 3 vs 1.38927398127)
Also, why are you vel.y = 0? that doesn't seem necessary.
Setting y to 0 gives "flat" on-the-ground speed. If you're going 30kph over a lot of up-and-down hills, you're maybe only making 25kph progress on the map. That sort of thing.