Add one object already create more than one time

It´s possible to add the same object more them one time without create the object again??
Ex: i have a box and want to repeat dat box but in a differente position.

Need to create other object like the one already created or exists other option?

There are lots of ways of doing this, but probably the simplest is the clone method.

const box2 = box1.clone();
box2.position = newPositionVector;

EDIT: the correct way of doing this is:

const box2 = box1.clone();
box2.position.copy( newPositionVector );

:sweat_smile:

1 Like

I try to use and no sucess…

const obj2= obj2.clone();
obj2.position(-1,3,1);

Try obj2.position.set(-1,3,1);

Have a read of the Vector3 docs to make sure you understand the correct methods of setting this.

1 Like

already try dat, i will investigate.
If you have any advice plz tell me

If you have any advice plz tell me

Sure, please make a live example that demonstrates your problem using this codepen as a starting point

https://jsfiddle.net/7bmqnrds/11/

box2.position.set=(5,3,5);

should be

box2.position.set(5,3,5);

oh okok thx man

How it works with function??

Exemp: I create a Function to create a object and i want to make another object like the one i create, can i use clone in the functions?! I can´t make it…

Also it´s possible to move a object between 2 points(a,b)??

Isn’t the position property set to no non-writable? At least in the version i use you can’t overwrite it, i needed to change the source for it.

2 Likes

the way @looeee said works for me

Oops, yes I think you are correct. In any case the correct syntax here should be

const box2 = box1.clone();
box2.position.copy( newPositionVector );