(Solved) Spherical collisionobject never stops and falls asleep

Hello!
I want to make a spherical object in my game behave approximately the way it should behave in the real world. And it is surprisingly hard to do. Imagine, for example, how a billiard ball behaves if it is hit with a cue. It will roll for a while and then stop completely. That is, its x and y coordinates will remain unchanged. In my case, inside the game the sphere does not stop completely and continues to roll very slowly to the left or right, as if some very weak force continues to push it. In box2d shouldn’t the physical body fall asleep completely after some time? Why isn’t this happening? Even if, when measuring the speed of the ball, I set angular velocity to zero

go.set("#collisionobject", "angular_velocity", vmath.vector3(0,0,0))

the ball still continues to make some micro-jumps and never falls asleep. Please advise what to do.
Game physics:


Ball physics (sphere):
изображение
Walls:
изображение

I just went through this same problem. My physics settings in my project are nearly identical (48 px = 1 meter).

Try setting Velocity Threshold in the Project Settings to 0. Don’t know if intended or a bug, but if Velocity Threshold is positive, my dynamic bodies never sleep or take many minutes to sleep.

Also, all the box2d settings are very, very sensitive and require a lot of tuning (such as Restitution, Linear Damping, etc.). It takes a long time to tune a dynamic physics game. Friction should be 0-1… I see a 3 on your static body. Seams between physics shapes also cause issues in box2d, even when perfectly aligned… combine colliders when possible.

So far I haven’t had to set Angular or Linear Velocity to 0 with a script. It just takes some tuning to get there.

3 Likes

Keep in mind that the Velocity Threshold parameter depends on the Scale of the physics. If you use scale = 0.01 for 2D game (I recommend it!), then velocity threshold should be 100, i.e. to have this parameter as 1 m/sec in Box2D internals as it’s set by default. Otherwise you will have all your bodies shaking like now.

1 Like

That will work well with a simple example like the original post. But as a project-wide setting, both Velocity Threshold and Contact Impulse Limit seem very limited in their use.

For example, with a range of different physics objects with different mass, bounciness, etc. these project settings seem to cause more edge case problems than they solve.

Trying to find a magic number that works with different objects, say a .5 kg plastic ball and a 20kg stone cannonball, is not practical. I ran into cases where a contact response never allows an object to sleep due to Velocity Threshold. These same objects resolve themselves and sleep within a few seconds when allowing them to remain elastic.

1 Like

Thank you, velocity threshold option helped me.