- Home /
how to find out speed in MPH with wheelcollider.rpm
This might be a noob question, but im making a speed limiter and i want to do this through wheelcollider.rpm. the problem is, wheelcollider.rpm alone gives a value over 1000. I learned somewhere that you need to divide certain numbers to get the speed in mph, or kmh. The thing is, i dont kbow what numbers to divide by. If anyone could list the method to find this out, it would be alot of help
Answer by NordSpirit · Aug 02, 2016 at 11:41 PM
Hi @BloodBTF, if you wanna get you speed on mph or kmh, you should know circumference (L) of your will, to take it you should multiply the radius (R) of you wheel on 2 and PI. For example if radius (R) of your wheel is 1 meter then circumference (L) will L = 2*PI*R or 2*3.14*1 = 6.28 m . Now we know that your wheel is rotate by 1000 rpm. So every rpm you wheel is move on 6.28 m. If now we multiply 6.28 on 1000 we take 6280 meters on minute, or 6.2 km\m or 6.2*60 = 372 kmh. One mhile is 0.62 kilomiters so to convert kmh to mph just multiply 372*0.62=230 mph. So simply code on C# is will be:
public void speedometer(){
float wheelRadius; // put here your wheel radius
int wheelRpm; // put here you rpm
float circumFerence; //here we will store the circumFerence
float speedOnKmh; // here the speed in kilometers in hour
float speedOnMph; // and here the speed in mhiles in hour
circumFerence = 2.0f * 3.14f * wheelRadius; // Finding circumFerence 2 Pi R
speedOnKmh = (circumFerence * WheelRpm)*60; // finding kmh
speedOnMph = speedOnKmh * 0.62f; // converting kmh to mph
}
And don't forget that in Unity one unit is equl 1 meter, to work physics fine.
Answer by diliupg · Jul 27, 2021 at 09:10 AM
(circumFerence * WheelRpm)*60
gives the answer in meters. Divide by 1000 to get Kmh. But this is not good to show in a speedometer or such cause the values fluctuate wildly! the best way is the get the rigidbody velocity. Do this.
Speedometer.speed = (float)(ds.rb.velocity.magnitude * 3.6)
No, that is NOT the best way, as that will give the velocity of the rigidbody REGARDLESS of whether it's connected to the ground and REGARDLESS of what direction you're traveling. If you're drifting the car will look like it's gaining speed even tho you're going sideways, which is in no way accurate to real life.
Your answer
Follow this Question
Related Questions
How to detect my car is drifting or not ? 1 Answer
Question about the speed in the cartutorial 0 Answers
How make breaks and maximum speed 0 Answers
Unity 5 wheel collider throttle "stuck". 1 Answer
Wheelcollider turns too sharply 0 Answers