OnTriggerEnter2D getting called earlier than it's supposed to
I have this code:
using UnityEngine;
using System.Collections;
public class DestroyProjectile : MonoBehaviour {
void OnTriggerEnter2D (Collider2D other)
{
if (other.tag == "Bullet")
{
Destroy (other.gameObject);
}
}
}
attached to a wall so when the player shoots at it, the bullet gets destroyed.
For some odd reason the OnTriggerEnter2D randomly gets called a split second before the bullet actually reaches the wall's box collider. So when running the game you can see the bullet randomly (emphasis on the word "randomly") disappearing before actually hitting the wall.
I've tried everything I could think of, from adjusting the bullet and the wall's colliders to using raycasts but nothing has worked so far.
I'd really appreciate it if someone could help me figure out what's causing this bug.
Your answer
![](https://koobas.hobune.stream/wayback/20220612095945im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem with hit boxes in 2D 0 Answers
How to disable a boxcollider2d temporary? 1 Answer
GameObject keeps colliding for sometime after being destroyed 1 Answer
Why nothing happens if a Box Collider enters a Trigger? 2 Answers
I need to at each OnTriggerEnter added a point, but it only adds one point. Please Help! 1 Answer