Vector3::add: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "This function is used to add a Vector3 to another Vector3. ==Syntax== <pre> vector.add(Vector3 otherVec); </pre> ===Required Arguments=== *'''otherVec:''' Vector3: The vecto...")
 
No edit summary
Line 7: Line 7:
===Required Arguments===
===Required Arguments===
*'''otherVec:''' Vector3: The vector to be added to the callee.
*'''otherVec:''' Vector3: The vector to be added to the callee.
== Returns ==
* {{RageType|Vector3}} The sum.


==Example #1==  
==Example #1==  

Revision as of 06:07, 31 May 2019

This function is used to add a Vector3 to another Vector3.

Syntax

vector.add(Vector3 otherVec);

Required Arguments

  • otherVec: Vector3: The vector to be added to the callee.

Returns

  • Vector3 The sum.

Example #1

Server-Side
const vec1 = new mp.Vector3(10, 30, 100);
const vec2 = new mp.Vector3(40, 20, 60);

const total = vec1.add(vec2); // total = {x: 50, y: 50, z: 160}

Example #2

This will throw all players 500 units into the air.

Server-Side
mp.players.forEach(player => {
    player.position = player.position.add(new mp.Vector3(0, 0, 500));
});

See Also