Search In
• More options...
Find results that contain...
Find results in...

# How to create a precise speedometer?

## Recommended Posts

There are many speedometers out there but unfortunately they don't suit me. Current mods calculate speed based on the position of the car and i want a speedometer that simulates the actual working of a car. Calculating the wheel rotation, multiplying by wheel size and converting to km/h or mph. I intend to use it on a roleplay server, this will be base for many Interactions between players and I've had many problems with flicking values and Desync so it needs to work properly and be simple at the same time.

Can you guys help me?

##### Share on other sites

Real cars work differently (or used to) because they didn't have the technology to know how fast they are moving in relation to the real world.What I mean by that, is they don't know where you are and where you were previously and how long it took for you to travel between those two points. It is only recently that GPS based speedometers have come into being and those will work the same way as the calculations do in GTA V. They will measure your position and then a fixed time later, they will measure it again. Using the time taken to travel that distance, will give you the speed you are travelling at.

*<snip>* Lots of useless waffle removed.

Edit: Actually, thinking about this, the current speed and velocity are already handled by the game and are properties of the Vehicle (or Entity) class. So all the current speedometers should be doing, is taking that velocity and using the time interval to get the overall speed per hour.

Here's some code I use in one of my display mods to get the speed:

```int displaySpeedMPH = (int)(CurrentVehicle.Speed * 2.236936f);
int displaySpeedKMh = (int)(CurrentVehicle.Speed * 3.6f);```

It can't get much simpler than that... I don't even use the time interval.

Just one final quote to clear up the confusion about how car speedometers actually work. Source: https://www.howacarworks.com/accessories/how-a-speedo-works

"A flexible drive cable inside a flexible tube links a small magnet inside the speedometer to the gearbox output shaft.

The magnet rotates with the shaft and its magnetic field attracts a metal drum to turn the speedometer needle against the force of a hair spring. The needle moves round the dial until the restraining force of the hair spring brings it to rest to give a reading of the road speed."

No tyres or wheel dimensions, or rotation speeds involved.

Edited by Guest

##### Share on other sites

I use several ways in my own mods:

I use some of the following

- Use the wheel speed and calculate the road speed using the tyre radius.

- Use the engine RPM and gearing ratio. Will be inaccurate if the clutch is used (idle, during shifting)

- There's a bunch of ways to figure out which wheels are powered so your best estimation would be to average the rotation speed of the powered wheels and multiply that speed with the tyre radius.

- There's also a dashboard readout thing that most cars have, but some cars miss this and that value would stay 0.0.

Edited by ikt

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×