Want to add enemy bullets; enemy particle collisions now affect player

Hi! I want to add bullets for the enemies to shoot back and I’m running into the following issue. This is in my player collision handler script:

    void OnTriggerEnter(Collider other)
    {
        StartDeathSequence();


    }

    void OnParticleCollision(GameObject @object)
    {
        StartDeathSequence();  
    }

In order to get the hit to register, I have to turn off Is Trigger on my ship’s collider, because Particle Systems apparently don’t recognise Trigger Colliders. The issue is that Unity doesn’t seem to differentiate between particle collisions here; although the enemy bullets destroy the player object and vice versa, my player ship’s bullets hitting the enemy now register as a hit on my player ship, destroying it. In other words, shooting enemies causes my ship to take damage.

Is there a means of differentiating here or is this just a limitation of the method used to make bullets for Argon Assault?

You will have to write something that handles the collision, Unity is just firing a message letting you know there was a collision along with some information.

That’s not what’s happening. StartDeathSequence(); is the intended outcome of the collision event; that works fine, it destroys the player ship.

The problem is I want to call the method StartDeathSequence(); when a particle collides with the gameobject. Specifically, when bullet particles from my enemy objects collide with the player ship.

This works fine as is, except that now, when particles collide with other gameobjects (i.e. when my player ship fires bullets at enemies), it also calls StartDeathSequence();.

In short, it appears that every particle collision in the scene is being registered by this gameobject.

Yes as I said it doesn’t know what it’s hitting, you have to do the checks yourself. Only trigger the StartDeathSequence if it’s the gameObjects you’re interested in.

Yeah, that’s what I’m asking, how do you this?

There are several ways of doing this, the easiest way I think would be checking the tag of the collided object.

If(other.tag == “Player”)
StartDeathSequence();
If(other.tag == “Enemy”)
// do something else

You will have to set the tags accordingly on your game objects and trigger things to work with your game, but that’s the basic idea.

Hope this helps!

Thanks for your help. I did try that earlier, and I have set the tag on the player ship. But when I do this, the collision doesn’t register at all.

    void OnParticleCollision(GameObject other)
    {
        if (other.tag == "Player")
        {
            StartDeathSequence();
            print("hit by particle");
        }

    }

To clarify, the enemies have their own collision detection script that works fine; this is on the player collision handler.

I think after reading about this some more I’m gonna leave it and continue with the next part of the course; I don’t think the project is set up for this as the requirement for the player ship to be a Trigger collider is at cross purposes with it getting hit by particles. Maybe when I’m more knowledgeable I’ll come back to it.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms