2D Object not being destroyed by Collision script

The Tripleshot object will hit the player and stop when i uncheck isTrigger on the Box Collider2D. When I check it the Triple Shot will go right through it and not be destroyed?
On the Player Spaceship
BoxCollider2d with Trigger
Player tagged as “Player”

On the Triple Shot
BoxCollider2D with trigger
Rigidbody2D with no gravity
Powerupscript

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Powerup : MonoBehaviour
{
    [SerializeField]
    float speed = 3.01f;


    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.down * speed * Time.deltaTime);


        if (transform.position.y < -4.6f)
        {

            Destroy(this.gameObject);

        }

    }


    private void OntriggerEnter2d(Collider2D other)
    {

        if (other.tag == "Player")

        {
            Destroy(this.gameObject);
        }

    }

}

Any ideas?
Thank you,

5413467--550026--tripleshot.JPG

It seems like it should work to me, but you can get rid of the “this,” since “gameObject” refers directly to the game object the script is attached to.

It doesn’t; the trigger is not registered, for some reason.

using UnityEngine;

public class Powerup : MonoBehaviour
{
    [SerializeField]
    float speed = 3.01f;

    private void Update()
    {
        transform.Translate(Vector3.down * speed * Time.deltaTime);

        if(transform.position.y < -4.6f)
            Destroy(gameObject);
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.gameObject.CompareTag("Player"))
        {
            Debug.Log(other.tag);
            Destroy(gameObject);
        }
    }
}

I had a similar problem which I posted in “physics” yesterday. I followed the collision chart to a tee. For what it’s worth, I restarted the engine, and now it works. Maybe you’ll be as lucky.

No luck for me. :frowning:

I’d really like to know what the problem is, why the trigger is not registered.

Any idea on how to fix it? It does collide with the object if I uncheck is trigger but is simply not destroying it.

It doesn’t even collide for me…

I restarted the project and no joy.

What version of Unity are you using?

I’m testing with 2020.1.0a20.

Have you tryed using OnCollisionEnter2D instead of trigger?

Also a thing to try is to add a rigidbody to both objects with colliders, because a collider on a gameobject without a rigidbody is considered static.

Just tried it (OnCollisionEnter2D) but did not work either

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Powerup : MonoBehaviour
{
    [SerializeField]
    float speed = 3.01f;


    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.down * speed * Time.deltaTime);


        if (transform.position.y < -4.6f)
        {

            Destroy(gameObject);

        }

    }


    private void OnCollisionEnter2D(Collider2D other)
    {

        if (other.tag == "Player")

        {
            Destroy(gameObject);
        }

    }

  
}

Tried that: no result.

Tried that too…

Two rigidbodys causes the powerup to simply push the player down,

2019.3

So this script does have the enemy being destroyed when it hits the player, and the bullets destroying the enemy… And it is exactly like the Powerip script and the same player is hitting both with the exact same physics in it .

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Destoyenemy1 : MonoBehaviour
{
    public float speedDown = 4.1f;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.down * speedDown * Time.deltaTime);

        if (transform.position.y < -6.1f)
        {
            transform.position = new Vector3(Random.Range(-13f, 13f), 7f, 0);
        }

    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            other.transform.GetComponent<Player>().Damage();
            Destroy(this.gameObject);
        }


        if (other.tag == "Bullet")

        {

            Destroy(other.gameObject);
            Destroy(this.gameObject);
        }
    }


}

Your original script has incorrect capitalization. You have it as “OntriggerEnter2d” where it should be “OnTriggerEnter2D”.

It doesn’t work with the right capitalisation either.

What’s the difference between the objects themselves?

So I was teaching class last night and had them do this project explaining there was a bug in the script, and when I helped one of the students I was shocked to see to it work for them and ti worked for all 20 students? Maybe it was the caps of just a error with the VS script I created?

This worked

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Powerup : MonoBehaviour
{
    [SerializeField]
    float speed = 3.041f;

    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.down * speed * Time.deltaTime);

        if (transform.position.y < -4.6f)
        {

            Destroy(this.gameObject);
        }
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {

            Destroy(this.gameObject);
        }
    }
}