playMaker

Author Topic: how to spawn random objects?  (Read 4044 times)

ilovelessons

  • Junior Playmaker
  • **
  • Posts: 70
how to spawn random objects?
« on: April 08, 2017, 06:15:40 AM »
hi,

does anyone know how to spawn an object randomly around a certain area.

I have an object and I want it to spawn out of thin air (like 3 or 4 at a time) are a certain area.  I didn't see any on Ecosystem... or maybe I missed it..

Thanks guys :D


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: how to spawn random objects?
« Reply #1 on: April 08, 2017, 06:35:18 AM »
I think you are looking for the "Create Object" action. It can spawn objects into the scene, from prefabs or objects within the scene. This can take a variable, so you can setup a variable here and assign it various prefab objects. Or you can use the "Get Random Object" action to choose a random object with a specific tag.

"Create action" can also take a position (vector 3) variable. If you need a random location, you can use the "random float" action. Change those floats into variables. This way, you can constrain the area.

I have a tutorial on placing random trees, which may help you out. It shows how to generate random floats and change them to vector 3s, so you can have things generate within a specific area. . Its pretty close to what you are thinking, except that my objects are not randomly chosen.

« Last Edit: April 08, 2017, 06:37:09 AM by tcmeric »

ilovelessons

  • Junior Playmaker
  • **
  • Posts: 70
Re: how to spawn random objects?
« Reply #2 on: April 08, 2017, 06:42:01 AM »
Thanks,

I am looking at it now... thanks :D