Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Pool balls don't lose velocity on impact with each other...

Discussion in 'Physics' started by riasillo, Jan 6, 2024.

  1. riasillo

    riasillo

    Joined:
    May 23, 2023
    Posts:
    59
    I have a 3D pool game. balls have sphere colliders and rigidbodies. all have same mass, drag, and angular drag settings. interpolate and continuous dynamic. same physics material.

    I have messed with bounce threshold and material bounces but I've settled on
    bounce threshold set to 0 so balls would bump off bumpers with ball bounce material to 0 because any amount caused un realistic bounce.

    The main issue is when balls collide the hitting ball does not lose anywhere near enough velocity. even with bounce material to 0.5 the hitting ball still chases hit ball and retains way too much velocity and the hit ball bounces off way too hard.

    Qball has force impulse applied. Qball and hit ball just keep going in same direction right next to each other.

    I applied a breaking force on Qball in opposite direction to collision and it works very nicely but all the other balls that are just rigidbodies and sphere colliders without scripts on them to control movement just don't behave properly when colliding with each other as they don't lose anywhere near enough velocity on impact. The energy is transferred to hit ball properly but it isn't taken from the ball doing the hitting.

    I have nice bumper action working and balls respond properly off that. But ball on ball is not realistic.

    It's really only noticeable when balls are hit in straight line. On angle you get tangent angle for hitting ball, but it still retains way too much velocity.

    A combination shot for example. Qball hits ball 1. qball slows because of opposite breakforce, ball 1 hits ball 2 and both run up table at same speed, but ball 1 should break. The balls are rotating on table, physics material, friction all work well with Qball or Qball and 1 ball, but the problem remains with other balls. Curious why the physics engine doesn't handle this properly.

    shouldn't need a breaking force on Qball or other balls...

    Am I missing something simple here?
     
  2. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    613
    If you set the ball bounciness to the equivalent of used chewing gum there is no wonder they don't behave like a typical pool ball.

    Bounciness of pool ball should be close to 1 not 0 or 0.5 .

    Once you have the balls correctly configured you can start thinking about collisions with side walls. Remember that collision is result of interaction between two objects. You need to configure not just ball material but also the wall material. Since the walls will be only interacting with balls, it doesn't matter too much if the wall material have unrealistic values. Also make sure you understand how unity calculates bounciness in case of collision between objects with different materials.

    Get a physics textbook and repeat the chapter about elastic and inelastic collisions. That way you won't have to randomly guess whats wrong and what's correct.
     
  3. riasillo

    riasillo

    Joined:
    May 23, 2023
    Posts:
    59
    appreciate suggestion. I do have a science background and know physics, so I had originally set bounciness to .9 for near ideal but bounciness was behaving very strange. bad jitter effect on table surface with any bounce setting even very low. If I set bounce threshold velocity high enough to stop that jitter, 0.1 or 0.2, then I would lose bounce off bumpers, even with 1 bounce on bumpers, so I had to set bounce threshold velocity to 0 for realistic bumper play and that caused jitter. Anyway, that's what led me down other path with 0 bounce and I had it basically dialed in except issue as described above. I've been messing the past hour with .9 bounce on ball again. set table surface to 0 bounce, that seems to have gotten rid of jitter. I originally had 0.1 bounce on table for jumped ball bounce effect so it didn't just stick back to table. That was jitter culprit there, bumpers have bounce of 0.6 right now. I just wrote a script to simulate a proper bounce for a jumped ball on table surface since I had to set that bounce to 0 to remove jitter. That's where unity loses me a bit, a ball with a bounce of .1 or .5 shouldn't bounce indefinitely on table? Aside from that, the main issue still with bounce of any level, .1 to 1. too much energy conserved in the ball that is hitting. when it hits other object, that energy should be mostly transferred to hit object, which it is, but it should also be subtracted from hitting object based on angle of reflection. If I hit a still ball perfectly straight with high bounce, ball bounces straight back right now and that's not good. with low bounce it follows at same speed... neither of those are realistic. so I tried half, and that's not real. etc. I'm going for an ultra real 3D pool experience. I'm pretty close but this conservation of energy thing is off and I figure there must be a setting that's just not set right? for record I have friction settings of .2, .3 on ball and table. working pretty good for spin response. also have balls set to angular drag of 1 to slow down as fast as possible and I'm happy with speed to come to rest. any other ideas.
     
  4. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    613
    With regards to jittering or instability you observe, since you will only have <20 physics objects which are mostly primitive shapes instead of arbitrary meshes you can probably increase the simulation rate quite a bit. Defaults are for a more general case which might have a lot more physics objects.

    Bounce threshold documentation clearly states setting the value too low can increase jitter. Did you try any values between 0 and 1?

    And what would be a reason for ball to stop bouncing. If you have a basic physics model with partially elastic collision any value 0<e<1 will result in geometric progression bouncing forever. For a practical game you sim need some kind of threshold where you say that's small enough bounce/ slow enough stop. So maybe don't set it to 0, set it to something that's low enough where it doesn't the game too much but not 0. Although there is also sleep threshold, you might get away if only one of them is 0. But that's probably not the only culprit for what you observed. A quick test shows that with low bounce threshold value, a ball remains jumping much higher than it should assuming geometric progression based decrease in velocity. Increasing physics simulation rate(decreasing the fixed timestep) reduces this height, and reducing it further allowed it to stop bouncing. I guess even with continuous collision the thresholds need to be large enough where simulation timestep is small enough to describe behavior while aproaching them.

    One more reminder about bounciness coefficient between objects of two different materials. The Unity default behavior is to use average of the two materials. Meaning that if balls have 0.9 and wall has 0 you get 0.45. It might be easier to manage it if you switch to minimum mode. That way value in ball material will represent ball/ball collision, and the lower value in wall material will be whats used for ball/wall collisions.

    If you are really aiming for ultra real experience and you have the skills, you might consider writing your own specialized physics sim. That way you can more freely choose your tradeoffs and where to use a more elaborate physics model. A pool game might not be the worst cases to do it since few balls colliding with each other and few boxes is as close to textbook scenario as you can get. Simplest cases for collision geometry only sphere<-> sphere and sphere<->box. Instead of every possible combination of half dozen different shapes with who knows how many edge cases. Small amount of moving objects, also means you might get away without any spatial query structures. You could probably make a lot more assumptions and use analytics solutions more often, than a general purpose game physics engine can. I also wouldn't be surprised if dedicated simulation which needs to handle only one type of objects could outperform the default physics engine.
     
    riasillo likes this.
  5. riasillo

    riasillo

    Joined:
    May 23, 2023
    Posts:
    59
    appreciate the write up. SLEEP THRESHOLD. You just hit a major issue. I just set that to 0 to test something. Setting it to 0 causes a problem in that the balls continue to move infinitesimally so I can't shoot again, but... one issue I was having with ball bounce set high at very low speeds with hard cut angles, the Qball was bouncing off static balls and static ball wouldn't move. It looked bad which was another reason I had abandoned the high ball bounce previously. I messed with the frictions and lowered them but nothing helped, now with high ball bounce they are both moving at low speed steep angle collisions. However, I will have to write a script to wake up sleeping balls as long as any balls are moving since clearly that's the cause of that issue.

    The strange thing with the jitter I was observing was while ball was rolling on table. It was because table had 0.1 bounce, that was enough to make vibrate while rolling. When I set table and ball to 0 bounce Now I'm using minimums. I have the ball set to .9, frictions to .1 .2. table bounce 0. bumper bounce 0.6. I have never touched the fixed time stamp but as per your suggestion I just cut it in half. I'll have to read up on acceptable ranges.

    My meshes are very light weight. I was able to make balls with just 3 different ball meshes. I'm pretty good with keeping builds light. my ball fbx are only 40kbs. Most the weight in my build is the pool hall decor textures but that's all static no colliders or physics.

    Now that I have the bounciness high again I need to ratchet down the forces big time. That will help me better assess this approach. will be interesting to see if the Qball loses more energy during transfer once I fix the sleep threshold and fixed time are changed. Appreciate the suggestion on the sleep threshold, uncovered an issue.
     
  6. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    613
    The meshes you use for graphics is irrelevant, unless you are also using them for physics colliders colliders.
     
    riasillo likes this.
  7. riasillo

    riasillo

    Joined:
    May 23, 2023
    Posts:
    59
    got it thanks. for record I'm settling in on about .6 for ball collision under normal gravity, anything higher is just way too much conserved energy for real world. made a simple script for the ball rigidbodies that I want to stay awake and also to stop movement and rotation when moving very slowly. by keeping awake they just keep moving ever so slightly but critical for them to be awake for low speed collision. appreciate the recommendation on the sleep threshold, made a huge difference in being able to use bounce property on balls for this game. when using bounce I noticed very high energy collisions" found a thread about raising default max depenetration velocity up to 1000 and that solved that issue. hope those configs help others at some point. also set bounce threshold to .005 and that solved sticky bumper issue for some reason at .001 it had glitchy issues, guess value was just too low. lot of little tweaking, seems more complicated than it needs to be, but it's pretty dialed in now.. thanks agian.
     
  8. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,562
    Ball collisions can likely remain high (almost totally inelastic), but felt on a billiard table has a significant stopping power for balls moving slowly. Thanks to the tiny fibers, it essentially extends the concept of static friction vs dynamic friction; at low speeds the fibers give more pushback than at higher speeds which easily overcome them.
     
    riasillo likes this.
  9. riasillo

    riasillo

    Joined:
    May 23, 2023
    Posts:
    59
    what type of dynamic and static settings would you assign a pool ball and a felt. I set the ball at .1 and .2 and the felt at .2 and .3 a new felt has more friction than you might suspect. it's what allows the spin on the ball to grab. I have torques applied to ball with a UI spin control system and it looks pretty good with settings I listed but curious to get take on what starting points you would guestimate.