E
E
Egorian2018-02-20 10:29:44
C++ / C#
Egorian, 2018-02-20 10:29:44

How to fix ground touch check?

I'm making a 2d platformer. I made such a system for checking for touching the ground:

public class GroundChecker : MonoBehaviour {

    private Character player;
    private void Start()
    {
        player = GetComponentInParent<Character>();
    }
     private void OnTriggerEnter2D(Collider2D collision)
       {
           if ( collision.gameObject.layer==8)//8 слой-слой с объектами по которым можно ходить
           {
               player.onGround = true;
              
           }
    
    }
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.layer == 8)
        {
            player.onGround = true;
        }
    }
//Проблемный участок//
    private void OnTriggerExit2D(Collider2D collision)
       {
           if (collision.gameObject.layer==8)
           {
               player.onGround = false;
      
           }
       }
    

}

My land consists of several blocks.
When a character jumps from one block to another, a jump animation plays for a few moments. How to change the check for leaving the "ground"?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Griboks, 2018-02-20
@Egorian

It is necessary to check if the character is standing on other blocks at the moment of exiting the block.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question