Jump to content

speedometer


Hugos

Recommended Posts

I have a function by means of which I learn car speed:

function GetSpeed()
	if isPedInVehicle(getLocalPlayer()) then
		vehicle = getPedOccupiedVehicle(getLocalPlayer())
		px, py, pz = getElementVelocity(vehicle)
		speed = ((px^2 + py^2 + pz^2)^(0.5)) * 111.847
		mph = math.floor(speed)
	else
		guiSetVisible(disc, false)
		guiSetVisible(needle, false)
	end	
end

I have a speedometer and an arrow (to watch pictures). How to make that the arrow was smoothly scrolled and specified what car speed now?

Spoiler

F7NSn92.pngQwxeyT6.png

 

Link to comment
6 minutes ago, WASSIm. said:

1) Your function is wrong

2) You need to use DX functions

You were helpful AF, bro :D Keep up the good work!

@Hugos
 

Use the getElementSpeed function from WIKI to get the current speed. It works quite well.

For the arrow of the speedometer:
You know that the speedo can show 260 max. You know the degree for the 0 on the speedo and the degree for 260. Now you can divide the current speed of the vehicle by 260 and then you get the relative number to multiply the degrees with.
So like:

local arrowRotation = 0; -- This will be the actual rotation of the arrow.

local vehicleSpeed = 180; -- This will serve as the current speed of your vehicle. You get this with getElementSpeed
local speedoMaxSpeed = 260;
local degreesFromZeroToMax = 180; -- This is the degrees between 0 and 260 for example

arrowRotation = (vehicleSpeed/speedoMaxSpeed)*degreesFromZeroToMax;

I hope it works. It's been a long time since I made something like this.

About dx. Yup! You HAVE to use dx for this.

  • Thanks 1
Link to comment
9 hours ago, WorthlessCynomys said:

You were helpful AF, bro :D Keep up the good work!

@Hugos
 

Use the getElementSpeed function from WIKI to get the current speed. It works quite well.

For the arrow of the speedometer:
You know that the speedo can show 260 max. You know the degree for the 0 on the speedo and the degree for 260. Now you can divide the current speed of the vehicle by 260 and then you get the relative number to multiply the degrees with.
So like:


local arrowRotation = 0; -- This will be the actual rotation of the arrow.

local vehicleSpeed = 180; -- This will serve as the current speed of your vehicle. You get this with getElementSpeed
local speedoMaxSpeed = 260;
local degreesFromZeroToMax = 180; -- This is the degrees between 0 and 260 for example

arrowRotation = (vehicleSpeed/speedoMaxSpeed)*degreesFromZeroToMax;

I hope it works. It's been a long time since I made something like this.

About dx. Yup! You HAVE to use dx for this.

Thanks!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...