Find command usage

Could I use the find command to detect all entities with a specific set x, y, and z coordinates? If not, how could I do this?

Hi @Nathan_Crouch and welcome,

Yes, you can do that it will work for example:

// example of filtering entities based on their position
const result = this.app.root.find( o => {
   if(o instanceof pc.Entity){
      const pos = o.getPosition();
      if(pos.x === coordX && pos.y === coordY && pos.z === coordZ) return true;
   }
});

Be careful though, if you have many entities definitely narrow down your search query (don’t search on root, search on the children of a specific entity). Or even better instead of doing this, keep a list of all the entities that potentially can be in the result set.

Thanks for answering @Leonidas ! How would I set the x y and z coordinates to check for with this method?

In this case just set some variables before executing find:

const coordX = 50;
const coordY = 10;
const coordZ = -15;

Just note if you aren’t using grid based coordinates then due to floating point precision you may need a more complex check for equality.

1 Like