Search Unity

[SOLVED] Rolling ball bounces on edge of adjacent platforms

Discussion in 'Physics' started by DJ-Coco, Dec 18, 2018.

Thread Status:
Not open for further replies.
  1. DJ-Coco

    DJ-Coco

    Joined:
    Apr 27, 2014
    Posts:
    47
    I know this problem is probably older than Unity itself and I found countless threads on this issue, but none of them delivered a satisfactory answer to me. In case you're not sure what I'm talking about, this is the problem I'm having:


    The ball is supposed to roll downhill but since it's a bouncy ball, it will bounce right off the edge. Even by removing the wall inbetween the two floors, the ball still bounces by colliding with the floor itself. I refuse to believe there is no solution to this, but by searching for an answer I only came across answers I can't implement.

    In most threads it was about a character getting stuck on edges which can apparently be fixed by making the collider round - obviously that's not exactly working here, since the ball already is round. I'm sure I could move across it seamlessly if it weren't for the bounce part, but unfortunately the bouncing material completely launches the ball off the course.

    Another idea was to combine the colliders - that unfortunately won't work either, since the reason these elements are separate is because the platforms move independently. I'm not sure dynamically combining them each frame is efficient, let alone possible - but let me know if I'm wrong in that regard.

    The last idea I heard was to give the floors no friction, but that didn't work out either.

    I could sort of circumvent the problems by increasing the fixed timestep, but the value I needed was so ridiculously low my game literally started to lag on a high-end PC - and even then it didn't entirely get rid of the bounce, so yeah... I guess it's safe to scrap that idea.

    I assume I have to include some "hack" that cheats the physics system, but I figured I'd ask around in case anyone has a better idea. :) Any ideas appreciated.
     
    Raptosauru5 likes this.
  2. For me, it was a solution to lower the incoming (bottom) collider a very little, the ball was still bumping but not upwards, it was a very little noticeable leap motion like when it bumping down one stair. But this depends on your physics, if your ball is "heavy" enough, you won't really notice too much. You can play around with the settings. Also if it's too hard to reset all of your physics, it's a solution to have a trigger right before the edge and change the physics settings temporarily in the trigger volume with script.

    But maybe other will have better ideas, I'm not an expert on physics. :)
     
  3. DJ-Coco

    DJ-Coco

    Joined:
    Apr 27, 2014
    Posts:
    47
    Thanks for your input!

    Moving the colliders downwards just slightly is subtle enough to not be noticable while getting rid of the bounce mostly. It's a great idea for this particular case, but I'm afraid it'll just postpone the problem until I'm at a stage where the platform can be crossed both ways and it's no longer a viable option.

    Triggers sound rather hacky but could work - I'm just not sure what properties exactly I would set. Nothing I messed with so far really got rid of the bounce - even by removing friction and bounce entirely it still knocks me off the ground, or at the very least, brings me to a halt.

    EDIT: I solved this issue by shifting the colliders dynamically. All the "tripping hazards" are now by default just slightly shifted downwards and warp upwards once the player can detect them by raycasting downwards.

    The platforms also warp the player, so the sudden movement doesn't mess with the physics - you'd still get some bounce otherwise by the platform ramming into you from the bottom.

    I fixed the renders of the platforms in place, so the only drawback is that the player seems to slightly move whenever he steps on one of these platforms, but it's much less jarring than getting knocked entirely off the course.

    Thanks for giving me the idea, LurkingNinjaDev. I hope my solution might also be useful for someone else struggling with this omnipresent problem.
     
    Last edited: Dec 18, 2018
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    Have you tested with two adjacent planes? I mean using the plane plane provided by Unity, menu GameObject > 3D Object > Plane.

    Also, are your colliders marked as Convex? If so, then they ball will probably bounce always, as removing the walls in between won't change the collider's shape.

    In summary, these are possible solutions / workarounds I can think of:
    • Use plane colliders (if the above test works) instead of using solid colliders.
    • Remove the Convex flag from the scenery colliders. Then, removing the walls in between will have some effect.
     
  5. DJ-Coco

    DJ-Coco

    Joined:
    Apr 27, 2014
    Posts:
    47
    Thanks for the input! I hadn't thought of the fact that MeshColliders were at fault removing the walls had no effect. It's a great idea, but I'm not sure it'd still work for when the wall is required (e.g. if the ball moved the other way)

    I happened to solve this issue just a few minutes before you posted (see my previous post for anyone looking for the solution I used) - but your idea is great too :)
     
    Edy likes this.
  6. clark_thomson2001

    clark_thomson2001

    Joined:
    Mar 25, 2019
    Posts:
    2
    Hi, I'm new to Unity, and kind of an amateur at coding. Came up with a sort of semi-solution, just not that experiences with altering the game objects. I was wondering if there was a way to 'router' all the edges so to speak, so that at least you could always guarantee a more reasonable impact than the 'phantom' knee-walls that seem to be causing the bounce between platforms? You could use a relatively small radius, un-noticably so if you have someone whos good at textures to somehow utilize the cut-out. Any-who, if anyone thinks this is a potential fix and knows how to do what I'm talking about, a reply would be great! thanks
     
  7. Rafael-Nesi

    Rafael-Nesi

    Joined:
    Nov 23, 2012
    Posts:
    1
    Hey, I know this is marked as solved, but I ran into the same issue (Unity 2021.3.5.f1 - A minigolf game I'm working on) and just in case it helps someone else, what fixed it for me was to modify the "Default Contact Offset" from 0.01 to 0.0001 in the Physic's settings.
     
    Mohak_dev and tuncaym like this.
  8. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    The only reliable fix for this I’ve found is setting the bounce of the ball to zero. This however results in a ball that does not bounce off walls as desired. To overcome this create two spheres for the ball. Use layers to mask the collision. One sphere has zero bounce and collides with the ground, the other sphere has full bounce and collides with everything else. Result, a perfectly predictable bounce off walls with predictable roll when it hits the ground.
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Solve one problem, create dozens more. You should consider the contact offset default is there for a reason. When/if you get other collision issues then recall that you changed this to a very low value and may need to restore it.
     
  10. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Yep,

    ultimately though, this is an issue inherent in physX. You will only be able to work around it, never solve it completely.

    there is another thread about the experimental physics contacts editing script api. I believe some have tried solving similar issues there.
     
    MelvMay likes this.
  11. tuncaym

    tuncaym

    Joined:
    Oct 3, 2022
    Posts:
    1
    that worked
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Please don't necro threads. If you want to show appreciation then please use the Like button instead.
     
Thread Status:
Not open for further replies.