Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help with 2d player character collision

Discussion in '2D' started by johnyfoxter, Nov 25, 2015.

  1. johnyfoxter

    johnyfoxter

    Joined:
    Nov 3, 2013
    Posts:
    21
    Hello everyone,

    what is the best way to detect collision with corner of next ground (red circle)?

    coll.jpg
     
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    If it has a box collider on the platform/ground the player will collide with the edge of an object as well as the top & bottom if they come into contact with it.
     
  3. johnyfoxter

    johnyfoxter

    Joined:
    Nov 3, 2013
    Posts:
    21
    If character don't jump so he will crash into next ground. How do I detect collision?
     
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    If he's not touching it there's no collision, if he's touching it then there's a collision. You can't detect a collision with the ground in the air if he isn't actually touching it.
     
  5. johnyfoxter

    johnyfoxter

    Joined:
    Nov 3, 2013
    Posts:
    21
    Yes,but he is touching ground and he will crash into next ground.
     
  6. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I don't understand what the issue is. If you have a box collider around the next ground he will hit the edge of it & not pass through it.
     
  7. johnyfoxter

    johnyfoxter

    Joined:
    Nov 3, 2013
    Posts:
    21
    How do I find different between front and bottom collider ? Because character can walk on top on ground. But he cannot touch ground from front.
     
  8. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I still don't understand why you don't want him to touch the ground from the side.

    Anyway, You can place a cube or something in front of the upper ground & turn the mesh renderer off so you can't see it or you can do a raycast down to detect what is under the players feet.
     
  9. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    theANMATOR2b likes this.