GetElementVelocity: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Server client function}} | |||
__NOTOC__ | __NOTOC__ | ||
==Description== | ==Description== | ||
Line 10: | Line 11: | ||
===Returns=== | ===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 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''. | ||
==Example== | ==Example== | ||
This example | <section name="Server" class="server" show="true"> | ||
This example retrieves, calculates, and displays the speed of a player named ''someguy''. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
--find a player named "someguy" and get his velocity. | -- find a player named "someguy" and get his velocity. | ||
speedx, speedy, speedz = getElementVelocity ( | speedx, speedy, speedz = getElementVelocity ( getPlayerFromNick ( "someguy" ) ) | ||
--use pythagorean theorem to get actual velocity | -- 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) | ||
--report the results. | -- report the results. | ||
outputChatBox ( "Someguy's current | outputChatBox ( "Someguy's current velocity: " .. actualspeed .. " arbitrary units." ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{element functions}} | {{element functions}} |
Revision as of 19:15, 19 August 2007
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
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.
Example
Click to collapse [-]
ServerThis example retrieves, calculates, and displays the speed of a player named someguy.
-- find a player named "someguy" and get his velocity. speedx, speedy, speedz = getElementVelocity ( getPlayerFromNick ( "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
- 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