Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Ball Bounce Physics Exit Trajectory

Discussion in 'Physics' started by enragedmrt, Sep 6, 2023.

  1. enragedmrt

    enragedmrt

    Joined:
    Oct 5, 2009
    Posts:
    95
    Hey all,

    I'm pretty seasoned in Unity but I have yet to try and use the physics system as a core game mechanic & in doing so I might be driving myself crazy. In this case, the mechanic is simply a bouncing ball. I've stripped back everything to the simplest example.

    In the gifs attached you'll see two balls that have the same rigidbody configuration. They are also simulated in the same scene, w/ the same floor physics material, etc. Everything is identical EXCEPT the launch trajectory. They are slightly different. Very, very, slightly different. I've also included the angular velocity magnitude & speed above the ball so as to better compare them, though I think it's likely unnecessary.

    What you'll see is that each ball has a very different bounce trajectory. One "reflects" almost perfectly the incoming trajectory. The other ends up w/ a more vertical exit trajectory, which seems quite incorrect. The only thing I could think of that would actually result in a more vertical bounce is if the ball had backspin - which it does not.

    Second to backspin, the only other difference I can see while debugging is that the sharper, "incorrect" bounce has more penetration. My guess is that more penetration results in a larger "de-penetration" force that is then added to the resulting velocity. Is that the case? If not, what is causing this sharp exit angle? If it is in fact because of more penetration, how can one expect a physical model to "feel" real if it has such unrealistic behavior in such a simple scenario?

    P.S. I totally plan on just writing my own simulation for this, as the physics engine seems unlikely to produce consistent enough results for a model that could be easily hand-built. Also, given it's a core mechanic & quite simple it makes sense to write my own kinematic code to ensure maximum control. I'm simply digging into this as an academic endeavor - I want to understand my tools thoroughly.

    "Good Bounce" - Exit trajectory near reflection of enter.


    "Bad Bounce" - Exit trajectory much more vertical.
     
  2. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    291
  3. enragedmrt

    enragedmrt

    Joined:
    Oct 5, 2009
    Posts:
    95
    Hey, a reply! Yayyyy :D.

    Yeah, I can totally try reducing the timestep. That will obviously result in smaller distances traveled per physics update and thus reduce penetration. In the end, I'll just end up writing custom kinematics for this so it's more stable. Increasing the fixed timestep isn't really tractable given performance constraints.

    Fwiw, I've tried all the collision detections schemes. This video was recorded w/ Discrete. Continuous speculative is worse & Continuous Dynamic results in the same behavior as Discrete.

    My main confusion is... is this really how this works? It's really baffling to me. It seems "trivial" to have the bounce occur "accurately" - but I imagine that's because I'm not writing a generalized physics engine. I know it's just a ball & should behave a particular way.

    In any case, I would have expected a continuous collision check to _stop_ the ball from penetration & reflect correctly....

    Thanks again for the reply!
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,513
    I'm not a 3D physics dev but I'm surprised by the penetration you're showing there too. I wonder if it's related to the target collider? Is this a simple MeshCollider plane? If so, maybe you could try a large BoxCollider.
     
  5. enragedmrt

    enragedmrt

    Joined:
    Oct 5, 2009
    Posts:
    95
    I believe these recordings are from a box collider. Fwiw, I don't think the collider would affect the amount of penetration. Should just be a function of physics time step & projectile speed. My confusion is simply that I wouldn't expect the amount of penetration to change how the collision is solved. In my mind, the penetration is re-wound, the collision point calculated, and the ball reflected - but that doesn't seem to be the case. I think it might be that the friction applied varies depending on the penetration as a frictionless physics material does not produce the same issues.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,513
    A MeshCollider is far more complex so depending on the contact points calculated for it, it could affect it but as you say, it's a BoxCollider primitive so that won't be it.

    The first thing here I'd be curious about would be the initial contact points it reports to see if they are inside the "ground". Contact points are more "support points" than anything i.e. points where impulses are applied to separate collider bodies and apply restituion/friction.

    I deal with 2D physics not 3D physics so I'm not sure how PhysX would change the Torque in this situation if the contact points were not on the exterior of the colliders in question.
     
  7. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    291
    Can you maybe try with Unity Primitives?
    I have tried myself with different angles and velocities and the bounces seem ok.

    upload_2023-9-11_9-5-16.png

    upload_2023-9-11_9-5-29.png