Finding random entity from array and making clones of it

i want get random object from array and make a clone of it but the clone functionality is not working fine, i’m new in playcanvas, so can anyone help me.

this.PuzzleArray = this.app.root.findByTag("Shapes");

console.log("PuzzleArray Length",this.PuzzleArray.length);

// this.RandomPuzzle = this.PuzzleArray[Math.floor(Math.random(this.PuzzleArray.length - 1))];

// console.log("RandomPuzzle" + this.RandomPuzzle.name);

 var RandomPuzzle  = 0.2;

 RandomPuzzle = Math.random() * this.PuzzleArray.length;

    this.puzzle = this.PuzzleArray[Math.floor(RandomPuzzle)];

    console.log("RandomPuzzle",this.puzzle.name);  

    var posX=this.Point1.getLocalPosition().x;

    var posY=this.Point1.getLocalPosition().y;

    var posZ=this.Point1.getLocalPosition().z;

    var cloneholder = this.puzzle.clone();

    cloneholder.enabled=true;

    cloneholder.setPosition(posX,posY,posZ);

    this.Point1.addChild(cloneholder);

    console.log("working");

    var RandomPuzzle1 = Math.random() * this.PuzzleArray.length;

    this.puzzle = this.PuzzleArray[Math.floor(RandomPuzzle1)];  

};

What’s not working? Do you get an error message? etc

clone is not working

@yaustar
you can check this
https://playcanvas.com/editor/code/959964?tabs=95003753&line=29&col=29&error=true

It’s a private project so I can’t access it

What do you mean by not working? Does it not appear? Is it in the wrong position? Do you get an error message etc?

@yaustar
i’m not getting any error, the console is working inside the code but i cant see any think happened.

One possible issue is that you are getting the localPosition here:

    var posX=this.Point1.getLocalPosition().x;
    var posY=this.Point1.getLocalPosition().y;
    var posZ=this.Point1.getLocalPosition().z;

But setting world position here instead of local:

cloneholder.setPosition(posX,posY,posZ);


i set it to local but still not working
cloneholder.setLocalPosition(posX,posY,posZ);

I’m shearing a my launch Screen Shot you can see nathing is appear.

Can you share the project or published build to take a look at please?

@yaustar
Are you there?

I am still waiting for this to help further?

i have an another issue
i want to add force in 2d sprite in z direction.

@yaustar
can you help me ?

Please create a new topic as it’s a different question