GetElementVelocity: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 14: Line 14:


==Example==
==Example==
--find a player named "someguy" and get his velocity.
<syntaxhighlight lang="lua">speedx, speedy, speedz = getElementVelocity ( findPlayer ( "someguy" ) )
<syntaxhighlight lang="lua">speedx, speedy, speedz = getElementVelocity ( findPlayer ( "someguy" ) )
--use pythagorean theorem to get actual velocity
--Raising something to the exponent of 0.5 is the same thing as taking a square root.
actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5)  
actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5)  
--Raising something to the exponent of 0.5 is the same thing as taking a square root.
--report the results.
outputChatBox ( "Someguy's current Velocity: ", actualspeed, " arbitrary units." )</syntaxhighlight>
outputChatBox ( "Someguy's current Velocity: " .. actualspeed .. " arbitrary units." )</syntaxhighlight>


==See Also==
==See Also==
{{element functions}}
{{element functions}}

Revision as of 15:01, 22 August 2006

Description

This function returns three floats containing the velocity (movement speeds) along the X, Y, and Z axis respectively.

Syntax

float float float getElementVelocity ( element theElement )

Required Arguments

  • theElement: The element you wish to retrieve the velocity of.

Returns

This function can fail if the element is a player in a car. Use the vehicle element in this case. It will also fail if the element specified does not have a velocity, or does not exist. If this function does fail, the first return value will be set to false. Other than that though, this function will return three floats that represent the element's current velocity along the x, y, and z axis respectively.


Example

--find a player named "someguy" and get his velocity.

speedx, speedy, speedz = getElementVelocity ( findPlayer ( "someguy" ) )
--use pythagorean theorem to get actual velocity
--Raising something to the exponent of 0.5 is the same thing as taking a square root.
actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) 
--report the results.
outputChatBox ( "Someguy's current Velocity: " .. actualspeed .. " arbitrary units." )

See Also