Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: ben135 on March 29, 2014, 08:09:03 PM
-
How can I make a certain object (an enemy in this case) spawn at a random rate from the same spot?
Thanks in advance.
-
Two states, first one is to create the enemy action, set float variable time to a random float using the action random float, next frame event action to the new state. In state 2 you create a waut action and you set the time to that random float variable, send event back to the first state and now you have a random loop to create enemies.
-
edit: Which action would I be using to spawn a new character model every time it loops?
-
you can use the action create object.
https://hutonggames.fogbugz.com/default.asp?W61
-
Got it thanks.
-
Sorry, for double post. I have another question.
I want to have the spawned enemies be deleted/removed when they walk into an invisible wall. Right now I have box collider and rigidbody set up on both objects (enemy character model and the invisible wall) with an FSM on the enemy character model (two states : 1. Trigger Event -> Destroy Self). After it destroys itself for the first time, the timed spawning FSM still runs but no character models actually appear. I see the spawning happen at the spawn spot but it immediately dissapears as if it couldn't find the character model to spawn. How can I solve this? Or maybe there's a better way to delete them as they touch another object?
-
Prefabs! So get the enemy and put into a new prefab folder in the project window and that will be your prefab. Place that prefab as the object to create and it will always spawn from there instead of from the game scene (which is why it can't create something that is now gone).
-
This is perfect. Thanks so much Sebaslive!
-
You're welcome!
-
How can I remove all the enemies generated from the spawn with a click?
Right now I have state 1 being activated with a click to state 2 : Activate Game Object action which works for the deactivating the spawn point but not the character models that were generated from the prefab. How can I solve this?
-
One way is to set all the prefabs as children to an empty gameObject and destroy that//deactivate that game object to get rid of them all.
-
How do I point my spawned prefabs as children to a gameObject?
-
whenever you create an object it gives you the chance to store that gameObject. After you create it you can go to a new state and set the parent to that gameObject by using set parent.
-
For some reason I can't set the parent of the prefab to the empty game object. Does it have anything to do with one belonging to the hierarchy (empty game object) and one belonging to assets (prefab)?
-
Right, you could set it by using a global variable. You can set the empty gameObject as a global variable and then in the random object that was spawned have the action set parent to that global variable. In the empty gameObject you use the action Get Owner and set it to that global variable.