Entity::getSpeed: Difference between revisions

From RAGE Multiplayer Wiki
(yay)
 
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
result is in meters per second<br><br>------------------------------------------------------------<br>So would the conversion to mph and km/h, be along the lines of this.<br><br>float speed = GET_ENTITY_SPEED(veh);<br>float kmh = (speed * 3.6);<br>float mph = (speed * 2.236936);<br>------------------------------------------------------------
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">entity.getSpeed();</syntaxhighlight>
<syntaxhighlight lang="javascript">entity.getSpeed();</syntaxhighlight>
=== Required Arguments ===
=== Required Arguments ===
* '''Entity:''' '''<font color='red'>vehicle</font>'''
===Return value===
===Return value===
*'''float'''
*'''MP/s (Meters per second)'''
 
==Speed Calculations==
*'''KM/H (Kilometers per hour):''' <code>speed*3.6</code>
*'''MP/H (Miles per hour):''' <code>speed*2.236936</code>
 
==Example==
==Example==
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// todo
 
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
}
</syntaxhighlight>
</syntaxhighlight>
==See also==
==See also==
{{Entity_function_c}}
{{Entity_definition_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]

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