playMaker

Author Topic: Random Object Spawn  (Read 6226 times)

ben135

  • Playmaker Newbie
  • *
  • Posts: 14
Random Object Spawn
« 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.
« Last Edit: April 01, 2014, 03:56:32 PM by ben135 »

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Random Object Spawn
« Reply #1 on: March 30, 2014, 02:27:44 AM »
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.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

ben135

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Random Object Spawn
« Reply #2 on: March 31, 2014, 01:22:06 PM »
edit: Which action would I be using to spawn a new character model every time it loops?
« Last Edit: March 31, 2014, 01:55:05 PM by ben135 »

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Random Object Spawn
« Reply #3 on: March 31, 2014, 02:21:37 PM »
you can use the action create object.

https://hutonggames.fogbugz.com/default.asp?W61
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

ben135

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Random Object Spawn
« Reply #4 on: March 31, 2014, 02:51:24 PM »
Got it thanks.
« Last Edit: March 31, 2014, 03:09:49 PM by ben135 »

ben135

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Random Object Spawn
« Reply #5 on: March 31, 2014, 05:20:33 PM »
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?

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Random Object Spawn
« Reply #6 on: March 31, 2014, 05:55:35 PM »
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).
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

ben135

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Random Object Spawn
« Reply #7 on: April 01, 2014, 01:41:53 PM »
This is perfect. Thanks so much Sebaslive!

« Last Edit: April 01, 2014, 01:45:03 PM by ben135 »

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Random Object Spawn [SOLVED]
« Reply #8 on: April 01, 2014, 02:24:00 PM »
You're welcome!
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

ben135

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Random Object Spawn [SOLVED]
« Reply #9 on: April 01, 2014, 03:56:07 PM »
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?

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Random Object Spawn
« Reply #10 on: April 01, 2014, 05:54:13 PM »
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.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

ben135

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Random Object Spawn
« Reply #11 on: April 01, 2014, 06:24:26 PM »
How do I point my spawned prefabs as children to a gameObject?

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Random Object Spawn
« Reply #12 on: April 01, 2014, 06:27:54 PM »
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.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

ben135

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Random Object Spawn
« Reply #13 on: April 01, 2014, 06:36:43 PM »
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)?
« Last Edit: April 01, 2014, 07:44:12 PM by ben135 »

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: Random Object Spawn
« Reply #14 on: April 01, 2014, 10:53:17 PM »
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.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez