# How to Eliminate or Reduce Physics Variability

I’m seeing a LOT of variability in the behavior of an object, more than I’ve noticed elsewhere, and I’d like to reduce it as much as possible. I need the object to behave (more) consistently every time.

The attached diagram shows the very simple set up which, in theory, should work very consistently every time (it does in real life). A ball rolls down a ramp, goes around a loop, then is caught by a funnel. If the ball is released from a height of 1.5x the diameter of the loop, it should have just enough energy to make it around the loop, theoretically. I want to position the funnel to catch the ball when it’s released from that height, but overshoot the funnel if the release height is very much higher.

The problem is, the speed of the ball after release is all over the place. Sometimes the ball lands in the funnel, sometimes it overshoots, sometimes it falls short. It’s never quite the same twice, and I can’t figure out any reason for that. I’ve seen variability before, but it seems much worse here. The ball is released from the same position, it has no velocity when released, nothing else is going on in the scene.

One other thing, maybe related. The 1.5x diameter release height assumes ZERO friction, but in Unity, the ball will make it around the loop if released from a much lower height. I had to add a small amount of friction to get it to behave realistically. Could that little bit of friction be adding to the variability? If I can’t make it behave more consistently, then this simulation is not going to work.

It will continue to be variable but you should use Fixed Update for the physics.

Sadly Unity is not the best physics deterministic engine.

Not sure what that that would apply to. I’m not doing anything physics-related in code in this case. Just positioning the ball, then turning isKinematic off and letting physics take over.

I’ve been playing around with both drag and friction, which I at first thought made it worse. But it looks like lowering friction and increasing drag can make it work just as realistically and reduce the variability a bit. Though it still seems to be more variable than other similar simulations. For example, on another level the ball is shot from a cannon into a funnel, and there’s very little variability. The ball might hit a tiny bit higher or lower on the funnel edge, but never so much variability that it misses completely.

Are you sure your releasing the ball at the same speed and the same location? If so I would try and give the ball more mass, and more angular and linear drag. This should keep the ball from acting too crazy more often. A drag of 2/2 should be fine. You’ll have to give it more force this way as well, good luck.

Yes, the ball is released from exactly the same position, set just before release. No force is applied to the ball, it just falls when kinematic is set to false. I’ve checked, and the velocity and angular velocity of the ball are zero just before release.

I’ve been doing some measurements, and found that friction and/or drag are adding the variability, both seem to be about the same. So they don’t just slow an object, but add noise as well. I’ve measured velocity as the ball’s leaving the end of the track and found that the bigger the loop, the more variable the velocity. The longer the ball is in contact with the track, the more variable its speed. I had originally been testing with the biggest of the loops, and it’s by far the worst. With smaller loops, there’s much less variability, low enough that I think it’s going to work. So I just need a way to deal with the biggest loop.

Here’s something odd I found: The biggest loop seems to have a “break-in” period. A new ball is released every few seconds, and the first few balls have a different velocity than the later ones. And the difference it pretty big. For example, with the biggest loop, the first three balls leave the track with a velocity of 6.2 - 6.5. The fourth and successive balls leave at a velocity of around 7.9. That’s a BIG difference, and I have no idea why it would just change like that. Frame rate seems to be pretty constant, and there’s nothing else going on in the scene, other than 3-5 other balls on other tracks. It’s going to make it tricky to compensate for.

What’s your Fixed Timestep? Increasing (edit: Decreasing) it usually increases physics consistency.
Are you using 3D or 2D physics?

It’s 3D physics, and the fixed time step is 0.01, max step is 0.015. I’ve played around with time step in the past, but more for accuracy than consistency. I’l give that a look.

BTW, wouldn’t decreasing it improve consistency? The smaller the step, the more accurate the collision detection.

You are right, I meant decreasing it (thereby increasing it’s frequency, which was the way I was thinking it).

Decreasing fixed timestep worked. Changing it to 0.005, while keeping max at 0.015, reduced variability on the large loop down to the amount I was seeing on the small loop. Interestingly, increasing the fixed timestep made it behave very strangely, with the ball getting stuck in the loop and just stalling.