Vector3::add
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