Alright so Im making a building mechanic. When the entity is enabled, I want it to make a clone, disable the main entity and have the clone play out a script. How would I do this?
Hi @Maximos_Finley! What would be the use case? From which entity or script do you want to clone?
i have a button, when you press it i want it to make a clone of the table model i have. and then the clone would go to where your mouse is until you click it and then it would stay in that position.
This requires some steps to do and I can’t explain them in detail because they depend on your setup.
You need to use a raycast to get the mouse position in the world.
https://developer.playcanvas.com/en/user-manual/physics/ray-casting/
If the raycast has a result, you can use for example result.point
as position for the clone.
Below a basic clone example.
var clone = this.app.root.findByName('Table').clone();
this.app.root.findByName('Root').addChild(clone);
clone.setPosition(result.point);
Maybe my Drag and Drop example project can also help you.
https://playcanvas.com/project/874243/overview/drag-and-drop