GetElementVelocity: Difference between revisions
No edit summary |
|||
(13 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
{{Server client function}} | |||
__NOTOC__ | __NOTOC__ | ||
This function returns three floats containing the velocity (movement speeds) along the X, Y, and Z axis respectively. This means that velocity values can be positive and negative for each axis. | |||
This function returns three floats containing the velocity (movement speeds) along the X, Y, and Z axis respectively. This | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">float float float getElementVelocity ( element theElement )</syntaxhighlight> | <syntaxhighlight lang="lua">float float float getElementVelocity ( element theElement )</syntaxhighlight> | ||
{{OOP||[[element]]:getVelocity|velocity|setElementVelocity|}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theElement''': The [[element]] you wish to retrieve the velocity of. | *'''theElement''': The [[element]] you wish to retrieve the velocity of. | ||
===Returns=== | |||
If succesful, returns three ''float''s that represent the element's current velocity along the ''x'', ''y'', and ''z'' axis respectively. 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. In case of failure, the first return value will be ''false''. | |||
The returned values are expressed in GTA units per 1/50th of a second[http://forum.mtasa.com/viewtopic.php?f=91&t=31225]. A GTA Unit is equal to one metre[http://gta.wikia.com/Unit#GTA3.2C_GTAVC_.26_GTASA]. | |||
==Example== | ==Example== | ||
<syntaxhighlight lang="lua">speedx, speedy, speedz = getElementVelocity ( | <section name="Server" class="server" show="true"> | ||
actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) | This example retrieves, calculates, and displays the speed of a random player. | ||
-- | <syntaxhighlight lang="lua"> | ||
outputChatBox ( "Someguy's current | -- get a random player and get its velocity | ||
speedx, speedy, speedz = getElementVelocity ( getRandomPlayer() ) | |||
-- 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) -- can be: math.sqrt(speedx^2 + speedy^2 + speedz^2) | |||
-- multiply by 50 to obtain the speed in metres per second | |||
mps = actualspeed * 50 | |||
-- other useful conversions | |||
-- kilometres per hour | |||
kmh = actualspeed * 180 | |||
-- miles per hour | |||
mph = actualspeed * 111.847 | |||
-- report the results. | |||
outputChatBox ( "Someguy's current velocity: " .. mps .. " metres per second." ) | |||
</syntaxhighlight> | |||
</section> | |||
==See Also== | ==See Also== | ||
{{ | {{element functions}} |
Latest revision as of 17:49, 25 May 2018
This function returns three floats containing the velocity (movement speeds) along the X, Y, and Z axis respectively. This means that velocity values can be positive and negative for each axis.
Syntax
float float float getElementVelocity ( element theElement )
OOP Syntax Help! I don't understand this!
- Method: element:getVelocity(...)
- Variable: .velocity
- Counterpart: setElementVelocity
Required Arguments
- theElement: The element you wish to retrieve the velocity of.
Returns
If succesful, returns three floats that represent the element's current velocity along the x, y, and z axis respectively. 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. In case of failure, the first return value will be false.
The returned values are expressed in GTA units per 1/50th of a second[1]. A GTA Unit is equal to one metre[2].
Example
This example retrieves, calculates, and displays the speed of a random player.
-- get a random player and get its velocity speedx, speedy, speedz = getElementVelocity ( getRandomPlayer() ) -- 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) -- can be: math.sqrt(speedx^2 + speedy^2 + speedz^2) -- multiply by 50 to obtain the speed in metres per second mps = actualspeed * 50 -- other useful conversions -- kilometres per hour kmh = actualspeed * 180 -- miles per hour mph = actualspeed * 111.847 -- report the results. outputChatBox ( "Someguy's current velocity: " .. mps .. " metres per second." )
See Also
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement