#Bug with 2D Colliders

1 messages · Page 1 of 1 (latest)

vocal shuttle
#

Hey ! I am trying to use Colliders in unity. Collisions with projectiles works perfectly for every hitbox so I assume that my Colliders are well-done. However, when the player is at the center of the map, for an unknown reason, he takes damages from enemies far away. It happens when the player is at (or almost) at the center of the map (0,0) and I don't understna why. At first, I used:

int count = rb.Cast(new Vector2(0,0), filter, new RaycastHit2D[10]);

But it caused the bug.
Then ChatGPT suggested

    Collider2D hit = Physics2D.OverlapArea(
        enemyCollider.bounds.min,
        enemyCollider.bounds.max,
        GameManager.instance.layerMaskList.characterProjectileLayerMask
    );
``` For a square box collider. But the bug is still there with this version.

Then I tried to detect directly with 
```csharp
int count = GetComponent<Rigidbody2D>().Cast(movement, filter, hits, 0);
``` But it detetcted "phantom collisions" as well

The only collision detection I found wasn't making any bug was with a static Physics2D.BoundCircle(transform.position, radius)
But this option is painfull to use for complex shapes, as it doesn't use the enemyCollider. So it isn't dynamic.

When I begin to use my enemyCollider, it seems to create the same bug.

Claude suggested to disable Queries Hit Trigger but it didn't work.
It also said that it was probably from unity itself. Is it possible ? Or is it just a simple thing that I don't understand in how unity works?

Help would highly be apppreciated 🙏
#

Bug with 2D Colliders

#

And I am using Editor Version 6000.4.1f1

echo vale
#

Doing a cast with zero vector as the direction is expected to not work reliably

#

What's the reason for manually checking collider overlap instead of using physics messages?

vocal shuttle
#

Is OnTriggerEnter2D one of them?

echo vale
#

yes

vocal shuttle
#

I tried to use it but there was no collision at all I probably used it in the wrong way

#

I'll try again and come back to you

#
    void OnTriggerEnter2D(Collider2D other)
    {   
        EditorApplication.isPaused = true;
        Debug.Log("Collided");
    }

I've tried to use this (in my enemy MonoBehaviour script) but it never pauses the game

vocal shuttle
#

Oh I forgot, I don't want the enemy to block the player, I want it to pass through the enemy but to detect the collision

echo vale