collision detection – Why does OnTriggerEnter2D/OnCollisionEnter2D work when there is no other collider object opposite?

my bullet:

  1. There is a Box collider (checked “is Trigger”)
  2. It has Rigidbody2D (Gravity = 0, freeze rotation Z)

View post on

I added the “OnTriggerEnter2D” function because isTrigger is checked. Bullet script:

private float lifeTime = 1.0f;

private void Start()
    Destroy(gameObject, lifeTime);

private void OnTriggerEnter2D(Collider2D collision)
    GameObject effect = Instantiate(hitEffect, transform.position, Quaternion.identity);
    Destroy(effect, 0.2f);

When I fire, the OnTriggerEnter2D function works even though there is no collider/object in the direction of the bullet. It only works a certain distance away from my main character, and it’s always the same no matter which direction I shoot.

Source link

More To Explore

The King’s Man

Don’t miss this really cool action packed TV spot for The King’s Man! The VFX are made by:BUFFramestore (VFX Supervisor: Chris Lawrence)Rhythm and HuesRISE (VFX

Share on facebook
Share on twitter
Share on linkedin
Share on email