playMaker

Author Topic: Cannonball/Projectile Problems [SOLVED]  (Read 3056 times)

coneilll89

  • Playmaker Newbie
  • *
  • Posts: 5
Cannonball/Projectile Problems [SOLVED]
« 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.
« Last Edit: April 20, 2013, 11:04:17 PM by Alex Chouls »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Cannonball/Projectile Problems
« Reply #1 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.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

coneilll89

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Cannonball/Projectile Problems
« Reply #2 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
« Last Edit: April 20, 2013, 09:47:06 PM by coneilll89 »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Cannonball/Projectile Problems
« Reply #3 on: April 20, 2013, 10:33:43 PM »
Alex will mark it when he sees it.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D