Filipe Costa Filipe Costa - 5 months ago 17
Javascript Question

Set and clone works differently

i have some doubts about Set and clone on Three js, im trying to render a scene where a sphere moves trought x axis and the camera follow the move with the lookAt, i tryed to do by myself the example on the book learning three js, but i didnt used the clone and my scene did the same but i couldnt see the sphere, with the clone i could see the sphere can someone explain me why that happen??

here is the 2 different codes:

sphere.position.copy(new THREE.Vector3(x,10,0));


sphere.position.set(new THREE.Vector3(x,10,0));


the first shows the sphere the second not :S

Answer

position is THREE.Vector3

look at reference and implementation

Vector3.set takes 3 values : numbers x,y and z

Vector3.copy takes Vector3