Y
Y
yraiv2021-01-08 10:54:46
Unity
yraiv, 2021-01-08 10:54:46

The character stands still, but exit and enter immediately work 2d colilsion?

The character falls on the blocks on which the earth tag hangs, but as soon as he touches them, the jump permission should turn on, and if he decides to jump or jump, it will turn off. When I run the program in the console, it first works that he entered the zone and the jump is allowed, but then it shows that he left (although he stands still)
the code:

void OnCollisionEnter2D(Collision2D coll)
    {

        if (coll.gameObject.tag == "Ground") 

        {
            groundCheck = true;
            Debug.Log("Прыжок готов");

        }
}
 void OnCollisionExit2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "Ground") 

        {
            groundCheck = false;
            Debug.Log("Прыжок выключен");

        }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2021-01-08
@freeExec

The character falls to the ground and at first "flies into it" - a collision is obtained. Then physics "pushes" him and he is now standing on the ground - the collision ends.

I
Ilya Valferov, 2021-01-08
@walfer2020

You can do it a little differently
https://www.youtube.com/watch?v=5vhMXhic2S8&t=1072s
somewhere in the 20th minute what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question