Hugos Posted August 14, 2019 Share Posted August 14, 2019 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 Link to comment
WASSIm. Posted August 14, 2019 Share Posted August 14, 2019 1) Your function is wrong 2) You need to use DX functions Link to comment
WorthlessCynomys Posted August 14, 2019 Share Posted August 14, 2019 6 minutes ago, WASSIm. said: 1) Your function is wrong 2) You need to use DX functions You were helpful AF, bro 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. 1 Link to comment
Hugos Posted August 15, 2019 Author Share Posted August 15, 2019 9 hours ago, WorthlessCynomys said: You were helpful AF, bro 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now