playMaker

Author Topic: How to spawn prefab in a circle?  (Read 6094 times)

RC

  • Full Member
  • ***
  • Posts: 148
How to spawn prefab in a circle?
« on: May 29, 2017, 07:47:40 PM »
Hello.

Im trying to figure out how to spawn prefab in a circle. Has anyone successfully done it,that can share how you did it? Thank you.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: How to spawn prefab in a circle?
« Reply #1 on: May 29, 2017, 10:00:43 PM »
You want to spawn multiple objects into the shape of a circle?

For example: 10 cubes that form a circle?

Then you will need to calculate the x/y/z positions for that circles points prior to the prefab placement. I am not sure playmaker itself can do that, unless you manually calculate them yourself before runtime. Do you need it to be dynamic?

RC

  • Full Member
  • ***
  • Posts: 148
Re: How to spawn prefab in a circle?
« Reply #2 on: May 30, 2017, 12:56:13 AM »
Thank you. I was afraid of that. I guess I'll just manually calculate the points for now. I don't think there is an action that playmaker have that can do that atm.

I do need it to be dynamic.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: How to spawn prefab in a circle?
« Reply #3 on: May 30, 2017, 01:10:27 AM »
Do you need this for 3d or 2d?

What part do you need to be dynamic? The amount of points on the circle or the size of the circle, or where the circle is in the world?

reference: https://stackoverflow.com/questions/24046402/trying-to-spawn-enemies-in-a-circle-around-the-player-in-unity

http://answers.unity3d.com/questions/714835/best-way-to-spawn-prefabs-in-a-circle.html
« Last Edit: May 30, 2017, 01:15:53 AM by tcmeric »

RC

  • Full Member
  • ***
  • Posts: 148
Re: How to spawn prefab in a circle?
« Reply #4 on: May 30, 2017, 01:25:44 AM »
It's for 2d,
the size of the circle.
I will check out the links. thank you.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: How to spawn prefab in a circle?
« Reply #5 on: May 30, 2017, 01:35:42 AM »
Not sure how good your c# is, but if you want, I can take a crack at it later. I would just change it into a playmaker custom action. (Providing the example code isnt too broke).


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: How to spawn prefab in a circle?
« Reply #6 on: May 30, 2017, 04:34:32 AM »
So from the script above I wrote this action. Maybe not exactly what you need, as the exact position of the prefabs are random (along the circle).

But you can set the radius, and center of the circle (centered around a gameobject), as well as the number of prefabs (and of course what prefab).

RC

  • Full Member
  • ***
  • Posts: 148
Re: How to spawn prefab in a circle?
« Reply #7 on: May 30, 2017, 10:04:22 AM »
No way! That's awesome! I can't wait till i get home from work to try it out.

THANK YOU!