When I insert a vector in an array and change the value of the vector, it also changes in the array. How can I safe data in an array in type of a vector without it changing the value when I change the value of the vector?
const array10 = [];
let vector = new THREE.Vector3(0,0,0);
array10.push(vector);
vector.x = 10;
console.log(array10[1]);
Output: (10,0,0)
CodePudding user response:
Put a copy of the vector in the array. A new vector3 with the same x, y, and z values can be created with clone()
:
array10.push(vector.clone());