GetDistanceBetweenPoints3D: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 25: Line 25:
vehicle1x, vehicle1y, vehicle1z = getElementPosition ( vehicle1 )
vehicle1x, vehicle1y, vehicle1z = getElementPosition ( vehicle1 )
vehicle2x, vehicle2y, vehicle2z = getElementPosition ( vehicle2 )
vehicle2x, vehicle2y, vehicle2z = getElementPosition ( vehicle2 )
outputChatBox ( "The distance between vehicle1 and vehicle2 is "..tostring(getDistanceBetweenPoints3D ( vehicle1x, vehicle1y, vehicle1z, vehicle2x, vehicle2y, vehicle2z )) )</syntaxhighlight>
outputChatBox ( "The distance between vehicle1 and vehicle2 is "..tostring(getDistanceBetweenPoints3D ( vehicle1x, vehicle1y, vehicle1z, vehicle2x,
vehicle2y, vehicle2z )) )</syntaxhighlight>
</section>
</section>


==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}

Revision as of 21:21, 14 November 2009

This function returns the distance between two 3 dimensional points using the pythagorean theorem.

Syntax

Click to collapse [-]
Server and client
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

Click to collapse [-]
Server and client

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 )) )

See Also