Creating instances of object


I’m sorry to keep bothering people with questions. Searching for the information in the documentation is frustrating though and I’m very grateful that people are willing to help me here.

I would like to have my experience randomly spawn several models of ghosts around a play area.

The model is in the hierarchy. I think I instance an object with the Z.Symbol(…) constructor. Anyone done this?

I know I can generate Bezier paths with Z.Bezier. Ideally I would like to have ghost models spawn on a series of preselected paths.

Am I thinking of this the right way?


This is my first experiment, which is meant to spawn a copy of an icon when I point a raycaster at it.

Yeah. Doesn’t work!

var instancenumber = 1;
var instancename: string = “ghost”+instancenumber;

parent.on(“intersectionenter”, (e) => {
// Runs when intersectionenter occurs on the parent node
// The argument e contains useful info about this event:

var instancenew = Z.Symbol(instancename);




Z.Symbol() works with symbols. So, the idea is to create an instance from a symbol (and not from a node already in the hierarchy), then push it to the hierarchy, something like:

var instance = Z.Symbol(ghost_symbol_name);// create an instance from a symbol


symbol.nodes.group_parent.push(instance);// add the instance to the hierarchy…

Here, you have a good example from @Mark: