2
votes

I have a 2D game. I have game objects that are made of a singular shapes with colliders and some that are made out of several shapes and included in an empty game object to which I have added a character collider. All the game objects have particle systems added and the single shaped game objects work as expected and explode onCollision, the multi shaped objects do not.

The explosions work as expected when using Play On Awake and Looping to Test them, but they do not explode onCollision. I have tried putting the particle system on one of the shapes inside the outer game object and then it shows an error Missing Component System, trying to access particle system for x object, which makes sense.

Within each game Object C# class I have the following methods:

private void OnCollisionEnter(Collision coll)
{
    Explode();
}

private void Explode()
{
    var exp = GetComponent<ParticleSystem>();
    exp.Play();
    GetComponent<Renderer>().enabled = false;
    Destroy(gameObject, exp.duration);
}

The bombs are set to a rate of 0, to go off in one burst.

I have tried searching and cannot find the missing information required when using particle systems in game objects that are made up from multiple 3D game object shapes.

What am I missing?

1

1 Answers

0
votes

I sorted it out, there were a few issues created from not understanding what to do and creating hacks.

The first issue is the renderers were being created in the child objects, so it was better to get all the child objects and loop through these and then disable the renderer in each of these.

I also removed the character colliders, as this was not needed and used sphere colliders.

I then unchecked is kinematic,as this had been enabled to stop my gameobjects in the air from being kicked about, instead I added mass in the rigid body.

In the explode method I commented out removing the rendering visibility as this had interfered with the explosion:

private void Explode()
{
    var exp = GetComponent<ParticleSystem>();
    exp.Play();
    //GetComponent<Renderer>().enabled = false;
    Destroy(gameObject, exp.duration);
}

I also extended the particle system start lifetime to exceed the duration. To ensure the particles were visible when the object is destroyed.

I'm still needing to tweak the explosions, but this has made a huge dent for me.