Playmaker Forum

PlayMaker News => General Discussion => Topic started by: RC on May 29, 2017, 07:47:40 PM

Title: How to spawn prefab in a circle?
Post by: RC 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.
Title: Re: How to spawn prefab in a circle?
Post by: tcmeric 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?
Title: Re: How to spawn prefab in a circle?
Post by: RC 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.
Title: Re: How to spawn prefab in a circle?
Post by: tcmeric 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
Title: Re: How to spawn prefab in a circle?
Post by: RC 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.
Title: Re: How to spawn prefab in a circle?
Post by: tcmeric 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).

Title: Re: How to spawn prefab in a circle?
Post by: tcmeric 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).
Title: Re: How to spawn prefab in a circle?
Post by: RC 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!