System::vdist2: Difference between revisions

From RAGE Multiplayer Wiki
(yay)
 
m (Add an image for visualization purpose)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Calculates distance between vectors but does not perform Sqrt operations. (Its way faster)
Calculates distance between vectors but does not perform Sqrt operations. (Its way faster)
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">system.vdist2(x1, y1, z1, x2, y2, z2);</syntaxhighlight>
<syntaxhighlight lang="javascript">mp.game.system.vdist2(x1, y1, z1, x2, y2, z2);</syntaxhighlight>
=== Required Arguments ===
=== Required Arguments ===
*'''x1:''' float
*'''x1:''' float
Line 12: Line 12:
*'''float'''
*'''float'''
==Example==
==Example==
<syntaxhighlight lang="javascript">
[[File:Mp.game.system.vdist2.points.png|800px]]
todo
<syntaxhighlight lang="js">
// see image above
 
// orange point
const x1 = 0;
const y1 = 0;
const z1 = 0;
 
// red point
const x2 = 0;
const y2 = 0;
const z2 = 2;
 
const vdist2Result = mp.game.system.vdist2(
    x1, y1, z1,
    x2, y2, z2,
); // returns (!) 4 (need to square root before using as a distance value)
 
const vdistResult = mp.game.system.vdist(
    x1, y1, z1,
    x2, y2, z2,
); // returns 2 (real distance between points)
</syntaxhighlight>
</syntaxhighlight>
==See also==
==See also==
{{System_function_c}}
{{System_s_function_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]

Latest revision as of 15:49, 12 November 2020

Calculates distance between vectors but does not perform Sqrt operations. (Its way faster)

Syntax

mp.game.system.vdist2(x1, y1, z1, x2, y2, z2);

Required Arguments

  • x1: float
  • y1: float
  • z1: float
  • x2: float
  • y2: float
  • z2: float

Return value

  • float

Example

// see image above

// orange point
const x1 = 0;
const y1 = 0;
const z1 = 0;

// red point
const x2 = 0;
const y2 = 0;
const z2 = 2;

const vdist2Result = mp.game.system.vdist2(
    x1, y1, z1, 
    x2, y2, z2,
); // returns (!) 4 (need to square root before using as a distance value)

const vdistResult = mp.game.system.vdist(
    x1, y1, z1, 
    x2, y2, z2,
); // returns 2 (real distance between points)

See also

Template:System s function c