Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

high travelling speed 2d character bumps up when hitting intersection of edge colliders

Discussion in '2D' started by killarkai, Feb 10, 2015.

  1. killarkai

    killarkai

    Joined:
    Apr 8, 2009
    Posts:
    23
    Hi there,

    I am trying to make a platformer with randomly generated blocks. When my character travels in high speed over them, it has a significant chance of bumping up when it hits the intersection of colliders.

    Screenshots:
    http://imgur.com/KP329tF,MBytAOe#1
    http://imgur.com/KP329tF,MBytAOe#0

    I realize that this is not a new problem, but all my searches so far point me to use edge colliders instead of box colliders (which I did), but in my case it didn't seem to solve any issues.

    I am moving the character by modifying rigidbody2d.velocity.x in FixedUpdate.

    Thanks for your help!
     
  2. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon Killarkia,

    Im not positive, but i would have thought the intersection of the edge colliders would give you the same ghost vertices problems, with the character kind of 'jumping', with hitting a corner sometimes.

    from your image are you using raycasting to handle collisions? or just the Collider? just that im seeing the two yellow vertical lines at the bottom corners.
    could you use raycasting to handle ground collision and then raise the players collider up slightly, might stop the juddering when traversing intersections.

    just my 10p ramblings there, thinking out loud :)

    edit:
    couple of the pages that I read about when i was doing something like this, albeit i was using box colliders tho. but same intersections impacted movement.
    http://issuetracker.unity3d.com/issues/collision-issues-when-using-2d-box-colliders
    http://deranged-hermit.blogspot.co.uk/2014/01/2d-platformer-collision-detection-with.html
    http://overdevelop.blogspot.co.uk/2013/12/2d-platformer-collision-detection-in.html
    http://www.iforce2d.net/b2dtut/ghost-vertices (just theory)
     
  3. killarkai

    killarkai

    Joined:
    Apr 8, 2009
    Posts:
    23
    I'm using colliders to handle collisions. The two yellow vertical lines are just used for detecting whether it is hitting the ground. (i'm not using the character controller) Currently I'm relying on Unity's physics2D systems, your suggestion of using raycasting to handle collisions sounds like more manual work for character control... but I'm stuck long enough to consider doing just that.

    Were you able to solve your issues using box colliders?
     
  4. Senladar

    Senladar

    Joined:
    Jan 1, 2015
    Posts:
    45
    I noticed this issue as well, my solution so far has been to put my world sprites under a "parent" and create a single box collider across the entire thing so there are no overlapping joints that you walk over.
     
  5. killarkai

    killarkai

    Joined:
    Apr 8, 2009
    Posts:
    23
    That would be a perfectly fine solution, alas the boxes and holes (no box in a tile) in my game are randomly generated, would be too painful for me to dynamically generate different size box colliders to contain these box tiles
     
  6. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Hopefully someone with more 2D experience than me will give you more guidance, but I only had a slow moving character in an old school platformer style.

    I used box colliders to composite my platforms, so I sort of had the same issue, but my player was hitting these intersections and was getting stuck now and again.

    I ended up using raycasting to handle character movement :(
    worked through tutorial from Sebastian Lague to pick that up.



    hopefully someone will get back with other alternatives for you,
     
  7. killarkai

    killarkai

    Joined:
    Apr 8, 2009
    Posts:
    23
    thanks, I also gave up after being stuck on this for 2 days.
    Ended up using raycasting to handle character movement too.

    for the record, I tried the following:
    - box colliders on tile boxes, edge colliders on character
    - edge colliders on tile boxes, circle collider on character
    - high mass on character
    - 0 friction and 0 bounce physics materials on everything
    - close to 0 min penetration for penalty settings
    - aligning the edge colliders between tile boxes with code (instead of by hand) to ensure that they are aligning properly

    but none of those were able to solve my problem.

    I must note though that when the character moves in slow speed it is almost perfect, but when in high speed the bump just happens too often.
     
    OboShape likes this.
  8. Senladar

    Senladar

    Joined:
    Jan 1, 2015
    Posts:
    45
    I was thinking about this this morning, what about checking your velocity vs. input?

    Basically, if you should be moving left/right but your x velocity is zero. Give a little bump to your Y to push you over whatever is getting you stuck in the physics engine.

    Code (CSharp):
    1. h = Input.GetButtonDown("Horizontal");
    2.  
    3. if (h <> 0 && rigidbody2d.velocity.x == 0){
    4.  
    5. rigidbody2d.addforce(0,0.01f);
    6.  
    7. }