Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: coneilll89 on April 20, 2013, 09:13:26 PM

Title: Cannonball/Projectile Problems [SOLVED]
Post by: coneilll89 on April 20, 2013, 09:13:26 PM
Hello,

I'm creating a 2D sidescroller in which the player has a cannon. I created a sphere for the cannonball, and each time the player presses a certain key I'd like to create a new cannonball object and lob it in the air.

I created one cannon ball (sphere) and created an FSM for it. As soon as the cannon ball comes into existence, i add a force to get it to fly in a nice trajectory. If it collides with either the ground or anything tagged as an enemy it destroys itself.

My issue is that one cannonball has to exist when i start my game. When it drops to the ground it destroys itself, taking the object and FSM with it (so I can't make a new one). If I press the key over and over as soon as I press play it will fire cannonballs like I want, until the original hits the ground and destroys itself. If anyone knows how I can fix this behavior, or if there is a tutorial somewhere on bullet/projectile creation, it would be much appreciated! Thank you very much.
Title: Re: Cannonball/Projectile Problems
Post by: Lane on April 20, 2013, 09:31:28 PM
Create a prefab in the project hierarchy and use that as your "create object" target.

It seems like the problem is you're using an object that is in your local scene hierarchy as your cannon ball but when it dies there is no reference object for it to clone. That's why you need to create a prefab, store it in the project hierarchy and put that as the target object to create. It doesn't exist so it can't be destroyed and will always remain available as a target for instantiation.
Title: Re: Cannonball/Projectile Problems
Post by: coneilll89 on April 20, 2013, 09:45:23 PM
Ah gotcha. I'm new to Unity, prefabs were in one of the tutorials I looked at but I haven't used them yet myself. I will go back and take another look at them. Thanks so much.

Edit: How do I mark this as solved? thanks
Title: Re: Cannonball/Projectile Problems
Post by: Lane on April 20, 2013, 10:33:43 PM
Alex will mark it when he sees it.