Search Unity

(stuck) Player collision to ignore edge collision

Discussion in '2D' started by x01kirbyx, Mar 21, 2017.

  1. x01kirbyx

    x01kirbyx

    Joined:
    Mar 21, 2017
    Posts:
    7
    Hello, im new to working with 2D and struggling to work with colliders. my player (sort of) is acting as a collider and partly gets stopped when collided with the edge collider (Images shown below is where im being stopped). However, I want the player to ignore the edge collider so it doesnt get stopped but, i want the players (small box in middle of player) Box collider 2D script to collide with the edge collider so that prevents walking through the object. hope i made sense. Pictures attached.
    stuck 1.jpg stuck 2.jpg
     
  2. webox

    webox

    Joined:
    Aug 27, 2015
    Posts:
    72
    I fail to understand your problem.. You say "you don't want the player to collide with the edge collider but you want the player to collide with the edge collider".. When you say the player you are reffering to the rest of the sprite outside the little box? As you present it, the only collider in the player is that little box, meaning that only that little box shouls collide with the edge collider.. Am I not understanding something?

    Edit: I see your issue now, but I don't think you're doing anything wrong, it should work as you expect.. I'll try to recreate the problem in the morning..
     
    Last edited: Mar 22, 2017
  3. x01kirbyx

    x01kirbyx

    Joined:
    Mar 21, 2017
    Posts:
    7
    i understand your confusion, what is happening is when the player's head hits the edge collider im being prevented from moving anymore up (as displayed on first picture) when i want the player to be able to walk onto the grass/dotted path but not on the wall so it looks like im walking next to it. in the second picture i understand there is a layering issue as i want to appear behind the wall and show the top half of the player but not be able to walk through the wall. So my solution was to create a small box collider in the center of the player so the top and bottom edge of the box collider when it touches the edge collder from either side of the wall it will prevent the player from passing through. But, it seems my player has got another collider or maybe a collider margin of some sorts going on as im being prevented going anymore towards the wall well before the small box collider in the center of the player collides with the edge collider. hope this helps, and thanks.
     
  4. webox

    webox

    Joined:
    Aug 27, 2015
    Posts:
    72
    Well what you thought is correct and should work as you think. Like this:

    Two boxes with rigid bodys 2D affected by gravity and one edge collider with no rigid body to make it static. The yellow one has a smaller collider:


    When I hit play:


    If I understand correctly this isn't happening for you and the spirteRenderer borders are being used as collider?
    I really can't see why is that happening to you.. I can give you a few questions
    • Are you using all 2D colliders?
    • are you using all 2D rigid bodys?
    • is there any OnCollisionenter code around? Could be doing weird stuff
     
  5. x01kirbyx

    x01kirbyx

    Joined:
    Mar 21, 2017
    Posts:
    7
    hi, yes the black box is the effect im looking to make, my player sprite has rigidbody2D and Boxcollider2D script. and the collision line in the wall just has the edgecollider2D script ill put a picture of the settings. i made the boxcollider2D on the player more shaped and dropped it with gravity but doesnt make any difference. The only code that changes the rigidbody2D was in my playercontroller script but i removed the script and it still does the same thing. The edge Collider on the wall was created in Tiled and exported with TiledToUnity. i'm just unsure where to look. Untitled.jpg
     
  6. webox

    webox

    Joined:
    Aug 27, 2015
    Posts:
    72
    Well that's odd.. Is there any chance you can upload a small version of your project soy I can take a look fo what's going on?
     
  7. x01kirbyx

    x01kirbyx

    Joined:
    Mar 21, 2017
    Posts:
    7
    Okay, ive understood the problem now, i created a new project and did the cubes and edge collider like you did and it did what i wanted. But when i zoomed in there is still a gap between the box collider and the edge collider but its not that noticable because of the scale unless its zoomed in on. where my project is scaled alot smaller the scale of 1 meter = 0.03125 as i wanted every block to be 32x32 pixels its alot more zoomed in so its alot more noticable.

    Edit: ive scaled my map to 1 and player to 1 and its working fine now, im just figuring out a way to have the player be behind a layer and infront of a layer
     
    Last edited: Mar 22, 2017
  8. webox

    webox

    Joined:
    Aug 27, 2015
    Posts:
    72