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

Problem: Circle Collider moving on even surface causes bounces

Discussion in 'Physics' started by Dorathor, Jul 25, 2018.

  1. Dorathor

    Dorathor

    Joined:
    Aug 28, 2017
    Posts:
    5
    Hi guys,

    A problem has been plaguing our devteam for quite a while. We're working on a physics-based 2D platformer, where you control a ball which moves across surfaces. We move the ball by adding an AddForce to the 2D rigidbody like so:


    GetComponent<Rigidbody2D>().AddForce(clickedPushDirection * pushPower * 167 * Time.deltaTime, ForceMode2D.Force);


    However, the result is that when moving along completely even surfaces, the ball would sometimes bounce slightly above the ground and then higher and higher and completely disrupt the movement controls doing so.

    This video illustrates the problem:


    The issue is even worse, when moving downwards Diagonal surfaces. Even if you input no force on your own, the ball will bounce and sometimes completely off the surface.

    What we have tried so far and looked into:

    Our first thought, was that if we apply force from upwards and into the ground, the ball would perhaps bounce. However this was not the case. If you apply force from directly up, nothing happens. Likewise, if we debug with commands to apply force directly from either side (left/right), the problem persists.

    Is speed the problem? From our tests, it would seem that the higher the speed, the more likely to happen, but it does happen at lower speeds as well.

    We have tried looking into the default 2D physics material that our surfaces use and playing around with friction and bounciness. The default settings (friction 0.4 and bounciness 0) seem to work best, but it doesnt seem like changing them, changes the problem.

    The ball uses a Circle Collider 2D and a Rigidbody 2D with AddForce as the movement.
    The surfaces use a tilemap collider where the sprites are a pixel perfect square.

    If you have any questions let me know.
     
  2. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    325
    I would say the problem is the surface.

    Try to disable the tilemap collider and use a boxcollider2d for all the surface.
    Sometimes, the joint between two colliders could create a collision.

    If the problem disappears with this solution, you can use this boxcollider2d. If you want to use the tile collider, maybe there are settings in the 2d physics settings that you can test.

    I have dropped a circle collider down a ramp made by a huge boxcollider2d and it seems to work fine.
     
    Hozgen90 and Dorathor like this.
  3. Dorathor

    Dorathor

    Joined:
    Aug 28, 2017
    Posts:
    5
    It would seem you hit the nail on the head right away! Removing the tilemap collider and making a gameobject with a BoxCollider2D completely fixes the problem.

    However an immense new problem has now arrived. Replacing all the maps in their entirety with gameobjects that consist of boxcollider2d objects seems like an immesurable task. Surely there must be a better way?
    And creating ramps like this seems impossible: https://prnt.sc/kbajb4

    Any ideas?

    We have been working with the tilemap collider for all of our maps and for different tilesets and layers and we have lots of tiles that arent just squares. What's the best approach? Or is there a fix for the tilemap?
     
  4. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    325
    Great!

    I have recreated your problem, making a huge ramp all with 1x1 boxcollider2d, and the problem appears.

    I am trying with the physics 2D settings, but without result, but the problem has to be fixed there. I don't know why, but my physics settings doesn't match with the Unity Documentation.

    Try some parameters and see if you can fix the problem.

    Good luck! ;-)
     
  5. Dorathor

    Dorathor

    Joined:
    Aug 28, 2017
    Posts:
    5
    ALRIGHT! So i actually managed to fix it completely and very efficiently!

    Apparently this has been a huge problem for quite a while for a ton of people. But quite recently Unity have added Composite Collider 2D and even more recently it now works with the Tilemap Collider 2D!

    Which means that a super simple and easy solution is as follows:
    Build your map with the built-in Tilemap functionality.
    Add a tilemap collider 2D(make sure your tiles have the correct Physics shapes).
    Add a Composite Collider 2D to the same GameObject.
    Then check the "Used by Composite" in the Tilemap Collider
    And voila! It should now create a composite line through the outline of your tilemap. All there's left is to fiddle with the settings inside composite collider 2D until it is satisfactory.
     
    u-doug and Maeslezo like this.
  6. domijezek

    domijezek

    Joined:
    May 13, 2021
    Posts:
    1
    Hello, I hope I don't miss anything... How would you do that in 3D please?