Kinematic and OnTrigger2D

Hello everyone :), in my game i have a kinematic rigidbody (my character) and a wall (kinematic). So, when my character touch the wall I want that my score increase by 1. But it don’t work =(, so i have put a debug.log to debug the function but the problem is the OnTrigger2D function. This is my code, the function “ContaPunteggio()” work fine so the problem is OnTriggerEnter2D() :

 void OntriggerEnter2D(Collider2D coll)
    {
        Debug.Log("Toccato");
        if(coll.GetComponent<Aeroplano>()!= null)
        {
            GameControl.control.ContaPunteggio();
           
        }
    }

Watch out that you wrote the method with small T, the correct is OnTriggerEnter2D (in case the wall’s collider is, in fact, a trigger)
If your character really hits the wall (that is, he can’t pass through it), then the wall has a collider that is not a trigger (what makes sense, since a trigger isn’t meant to be collided with), so the OnTriggerEnter2D won’t be called at all.
Instead, if it’s not a trigger, use OnCollisionEnter2D:

void OnCollisionEnter2D(Collision2D coll) {
    Debug.Log("Toccato");
    if(coll.GetComponent<Aeroplano>()!= null){
        GameControl.control.ContaPunteggio();
    }
}

PS: this:

if(a == b){

is better than this:

if(a == b)
{

Jokes aside, hope that helps :slight_smile: