Entity::getSpeed: Difference between revisions

From RAGE Multiplayer Wiki
 
(2 intermediate revisions by one other user not shown)
Line 20: Line 20:
let speed = vehicle.getSpeed();
let speed = vehicle.getSpeed();


speed = speed * 3.6; // Transform the speed in to KM/H
speed = speed * 3.6; // Transform the speed into KM/H
// If you want a realistic calculation for the vehicle speed use: speed = Math.ceil(speed * (speed / 20) * 2); <- this will raise up to 380 km/h for a T20, but you can still easily cruise around with 60 km/h
// If you want a realistic calculation for the vehicle speed use: speed = Math.ceil(speed * (speed / 20) * 2); <- this will raise up to 300 km/h for a T20, but you can still easily cruise around with 60 km/h


return speed; // returns the speed in KM/H
return speed; // returns the speed in KM/H
Line 28: Line 28:


==See also==
==See also==
{{Entity_function_c}}
{{Entity_definition_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]

Latest revision as of 18:07, 1 May 2024

Syntax

entity.getSpeed();

Required Arguments

  • Entity: vehicle

Return value

  • MP/s (Meters per second)

Speed Calculations

  • KM/H (Kilometers per hour): speed*3.6
  • MP/H (Miles per hour): speed*2.236936

Example

function getspeed() {

let vehicle = mp.players.local.vehicle
let speed = vehicle.getSpeed();

speed = speed * 3.6; // Transform the speed into KM/H
// If you want a realistic calculation for the vehicle speed use: speed = Math.ceil(speed * (speed / 20) * 2); <- this will raise up to 300 km/h for a T20, but you can still easily cruise around with 60 km/h

return speed; // returns the speed in KM/H
}

See also