Search Unity

Best detection method for 2D collisions between player and environment.

Discussion in 'Scripting' started by Penkine, Feb 2, 2020.

  1. Penkine

    Penkine

    Joined:
    Jun 5, 2019
    Posts:
    15
    I have a player which has a box collider and a rigidbody, and the environment will also have a collider on each section.
    What are some robust methods for tracking whether or not the player is on a certain surface?
    Any help? I'm pretty new and am not sure what to do.
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @Penkine

    "I'm pretty new and am not sure what to do."

    Did you watch any of the basics tutorials - I'm asking because all of this is explained there.

    One way you can detect your collision is with OnCollisionEnter2D and the same for exiting collision with OnCollisionExit2D.

    But I'm not sure which one is the question:

    "2D collisions between player and environment"

    or

    "tracking whether or not the player is on a certain surface"
     
    Penkine likes this.
  3. Penkine

    Penkine

    Joined:
    Jun 5, 2019
    Posts:
    15
    I have looked into that and it does work yes, but I come to an issue when I need to recognize if the player is in water.
    That should work for ground environments, I am wondering how to use such a system for, water for example.