Collision of arrows does not work

Hello my collider of bullets does not work as intended almost all bullets collide but some of them just passes in some angles any help is highly appreciated :slight_smile:

private void OnTriggerEnter2D(Collider2D other) {
        EnemyHealth enemyHealth = other.gameObject.GetComponent<EnemyHealth>();
        Indestructible indestructible = other.gameObject.GetComponent<Indestructible>();
        if(!other.isTrigger && (enemyHealth || indestructible))
        {
            Instantiate(particleOnHitVFX,transform.position,transform.rotation);
            Destroy(gameObject);
        }
    }

it hits enemies and pass over any object as intended but sometimes goes between grid as i didnt add composite collider and continuous collision detection. Only thing i can think of is because i have 2 ontriggerenter2d on bullet object. Other one is damageresource class which basically ontrigger checks if the object is enemy and if the answer is yes damages them

private void OnTriggerEnter2D(Collider2D other) {
        EnemyHealth enemyHealth = other.gameObject.GetComponent<EnemyHealth>();
        enemyHealth?.TakeDamage(damageAmount, knockBackAmount);
    }

Its detecting collusions as intended :confused: (First one is enemy health second one is indestructable)


image
image
image

Not having these things active can cause the bullets to slip through colliders. This is especially common if your framerate is low, because non-continuous detection works by comparing the position before moving the object and the position after and determining if a collider exists in the new position. Continuous detection checks all the points inbetween to ensure that we don’t wind up “skipping” a collider.

That being said, your screenshots show that you have both of these things on.

Actually, you could have as many classes as you wanted responding to OnTriggerEnter, they would all get called as long as they are on the same GameObject as the Collider2d.

Do you have an Indestructible component on the TileMap layer?

Hello first of all thank you so much for the answer! Yes I have indestructable class on the foreground(I tested it) and %90 of the time it collides but in some angles it just passes easily without colliding.

And that’s with Continous collision active on the Rigidbody?

Yes unfortunately :frowning:

This one may be hard to diagnose from a distance. Zip up your project and upload it to https://gdev.tv/projectupload and I’ll see if I can figure out what’s going on. Be sure to remove the Library folder from the Zip to conserve space.

Hi sent my github repo link using the link you provided thank you so much :slight_smile:

I took a look at your project, and I think the issue really is just a matter of speed overloading the physics system. Even with the extra options checked such as continuous collision, it’s possible to overload the physics system.

In this case, your arrow’s speed was set fairly high, I think 24? While blocking happened in most shots, there were still shots capable of taking out the three bushes on the ledge.
When I lowered the arrows speed to 15, they never got past the colliders at any time. The only issue there is that your character is moving at 15 as well, which is pretty fast.

Oh I understood but can i ask if there is any way to prevent high speed objects to break physics? Because i saw games that collusions works for high speed bullets.

Usually using larger colliders. The Tile collider/composite colliders as well as any non-standard shape style colliders have to use more complex calculations to determine a collision, where determining a collision with primitive shapes (square and circle) are easier to detect.

For instant shots, like true bullets where the naked eye cannot actually see the bullet, only the resulting hit, it is common to use a Physics2D.RayCast. These are generally extremely accurate, but each Raycast comes at a cost in performance, so making a lot of them can slow down a game considerably.

1 Like

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

Privacy & Terms