OnTriggerEnter2D

Hi, sry for this question. I know it’s full but i not found solution in other post…

I’m doing a simple endless runner but my triggerEnter2D not working. Now i explain what i do in my project:

I have a immobile Obstacle that have a Collider2D and Rigidbody2D (unchecked simulated) with a script that use OnTriggerEnter2D:

    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("enter");
        /*if (collision.CompareTag("SpawnOffArea"))
            this.gameObject.SetActive(false);*/
    }

I have a square object with Collider2D trigger that attached at camera.
My camera follow the player with this function in Update method:

    private void FollowPlayer()
    {
        this.transform.position = new Vector3(player.transform.position.x + offset, 0, this.transform.position.z);
    }

I had tried to use rigidbody also and only on the Collider trigger but nothing.

But it doesn’t trigger anything and I don’t understand why. (I have verified that the Z axis is the same and it is, except camera.)

Physics2D settings seem fine (I also reset).

(someone can change title in “OnTriggerEnter2D not triggered” pls?)

It’s out of the simulation. It doesn’t work if it’s out of the simulation, that’s the whole point of that option.

This isn’t the source of your issue but just don’t do this. If it moves in 2D physics, move a Rigidbody2D via its API, never modify the Transform. We have selectable body-types for this on the Rigidbody2D. Doing this causes the whole collider to be recreated whenever you modify the Transform.

Ty! now work! me noob :smile:

Thx, i have applied the change.

1 Like