Difference between revisions of "GetDistanceBetweenPoints3D"
From Multi Theft Auto: Wiki
(→Syntax) |
m (Reverted edits by MaStFa (talk) to last revision by AlexTMjugador) |
||
(One intermediate revision by one other user not shown) | |||
Line 6: | Line 6: | ||
==Syntax== | ==Syntax== | ||
− | <syntaxhighlight lang="lua">float getDistanceBetweenPoints3D ( float x1, float y1, float z1, float x2, float y2, float z2 )</syntaxhighlight> | + | <syntaxhighlight lang="lua">float getDistanceBetweenPoints3D ( float x1, float y1, float z1, float x2, float y2, float z2 )</syntaxhighlight> |
===Required Arguments=== | ===Required Arguments=== |
Latest revision as of 13:19, 22 July 2019
Note:
This function is equivalent to the Vector3 class getLength method when used with a vector that holds the direction and distance between two points. In other words, it produces exactly the same result as substracting the points' coordinates and getting the length of the result vector.
This function returns the distance between two 3 dimensional points using the pythagorean theorem.
Syntax
float getDistanceBetweenPoints3D ( float x1, float y1, float z1, float x2, float y2, float z2 )
Required Arguments
- x1: The X position of the first point
- y1: The Y position of the first point
- z1: The Z position of the first point
- x2: The X position of the second point
- y2: The Y position of the second point
- z2: The Z position of the second point
Returns
Returns a float containing the distance between the two points as a float. Returns false if an argument passed was invalid.
Example
This example gets the distance between two vehicles and outputs it to the chat box.
vehicle1x, vehicle1y, vehicle1z = getElementPosition ( vehicle1 ) vehicle2x, vehicle2y, vehicle2z = getElementPosition ( vehicle2 ) outputChatBox ( "The distance between vehicle1 and vehicle2 is "..tostring(getDistanceBetweenPoints3D ( vehicle1x, vehicle1y, vehicle1z, vehicle2x, vehicle2y, vehicle2z )) )
getDistanceBetweenPoints3D can also be used to measure the length of 3 dimensional vectors. This example calculates the speed of a vehicle by measuring the size of the it's velocity vector:
speed = getDistanceBetweenPoints3D ( 0, 0, 0, getElementVelocity ( vehicle ) )
Lua note: Using multiple return values as arguments for another function can only be done at the end of the argument list.
See Also
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace
- debugSleep
- decodeString
- encodeString
- fromJSON
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getFPSLimit
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getServerConfigSetting
- getTickCount
- getTimerDetails
- getTimers
- gettok
- getUserdataType
- getVersion
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setServerConfigSetting
- setTimer
- sha256
- split
- teaDecode
- teaEncode