Vector3::add: Difference between revisions
(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 |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
This function is used to add a Vector3 to another Vector3. | This function is used to add a Vector3 to another Vector3 or scalar. | ||
==Syntax== | ==Syntax== | ||
<pre> | <pre> | ||
vector.add(Vector3 otherVec); | vector.add(Vector3 otherVec); | ||
vector.add(number scalar); | |||
</pre> | </pre> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''otherVec:''' Vector3: The vector to be added to the callee. | *'''otherVec:''' Vector3 or number: The vector or scalar to be added to the callee. | ||
== Returns == | |||
* {{RageType|Vector3}} The sum. | |||
==Example #1== | ==Example #1== | ||
| Line 19: | Line 23: | ||
==Example #2== | ==Example #2== | ||
{{ServersideCode| | |||
<pre> | |||
const vec1 = new mp.Vector3(10, 30, 100); | |||
const scalar = 20; | |||
const total = vec1.add(scalar); // total = {x: 30, y: 50, z: 120} | |||
</pre> | |||
}} | |||
==Example #3== | |||
This will throw all players 500 units into the air. | This will throw all players 500 units into the air. | ||
{{ServersideCode| | {{ServersideCode| | ||
Latest revision as of 06:15, 31 May 2019
This function is used to add a Vector3 to another Vector3 or scalar.
Syntax
vector.add(Vector3 otherVec); vector.add(number scalar);
Required Arguments
- otherVec: Vector3 or number: The vector or scalar 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
Server-Side
const vec1 = new mp.Vector3(10, 30, 100);
const scalar = 20;
const total = vec1.add(scalar); // total = {x: 30, y: 50, z: 120}
Example #3
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
- Functions
- Properties
- Vector3::x
- Vector3::y
- Vector3::z