[Share] Exploding ship on death

Just wanted to share how I managed to have the ship blow apart on death.

https://i.imgur.com/VgZlIep.gifv

  • I created a new Asset of my ship, named it something else
  • removed the script and sound from it
  • added it to the scene so I could edit it.
  • added a RigidBody to each of the individual parts I wanted to break off as one piece.
  • Removed the RigidBody from the parent object
  • added a empty object inside the broken ship with a sphere collision, to help it break apart
  • Coded it:

[SerializeField] GameObject shipParts;

void OnCollisionEnter(Collision collision){
// kill
Instantiate(shipParts, transform.position, transform.rotation);
Destroy(gameObject);
}

Also make sure to select your real ship, you’ll see the rocket script has a Ship Parts member. Make sure to set that to the asset of the broken ship.

Privacy & Terms