Slowing moving sphere meshes

I’ve recently started using babylonjs and am really liking it so far.

I’m wanting to build some billiards games, so working with moving spheres is going to be key to setting up various scenes. I’ve got this so far with a basic table and some pool balls, but I can’t seem to get them to stop rolling, regardless of how much friction I add to the table top, or with dampening or slowly reducing the linear/angular velocity.

Any general input on naturally slowing these moving spheres would be really helpful. Apologies if this has been asked before, but I may not be familiar with the tags I need to be searching.

1 Like

Well, of course after posting I found a post about it. Usuing their advice, I ended up creating a loop that checked all meshes and scaled down the angular velocity:

for(var i in scene.meshes) {
	ball = scene.meshes[i];
if(ball.physicsImpostor.getAngularVelocity() != BABYLON.Vector3(0,0,0)) 

It doesn’t quite look organic to me, but with some work on the restitutions and frictions, I think I can get it figured out.

1 Like

Hiya J, welcome to the forum. Friction… on spheres… is almost non-existent… because they don’t have enough surface area at the contact-point with the table. Your found solve is perfect… except…

Perhaps… create an array called balls.

var balls = [];

Each time you create a new ball… balls.push(newBall);

Then… for your within-renderloop velocity damper…

for (ball of balls) {

That’s all. You don’t care if the ball is already fully stopped, do the “angular damping” on the stopped ball, too… it won’t care. :slight_smile: It removes an IF/THEN from your code.

(To be truthful, I don’t know if you will gain or lose performance by damping already-stopped balls. You might want to test that… maybe in a browser’s “profiling” system… in f12 dev tools area.)

ALSO… feel free to try the same exact code, except use LinearVelocity instead of AngularVelocity.

And maybe try a little bit of both… at the same time. Damp-down both… .99 or .98… or whatever. I think either method will work, and so will a combination.

Simulating that table felt… is not easy, eh? That fuzzy stuff has a mind of its own, sometimes. The pure math of the physics engines has a difficult time being “fuzzy”. :slight_smile:

Welcome again… good to have you with us! Good luck on your project! Write back as wanted, of course. Nice job on the found solution. Please mark thread as solved… if/when it becomes true. :slight_smile:

PS: I think… way down deep… in the bowels of the physics engine… there is also linear and angular damping on the rigidBody-class objects. To ref a “native” rigidbody within BJS…

mesh.physicsImpostor.physicsBody. That will return an object that is not from BabylonJS-land. And I don’t gaurantee that you will find damping properties deep in the physics engine… but maybe. :slight_smile:

Thanks for the response and tip about the array, will be working on consolidating creating the ball set and that’ll help get rid of the other meshes from the render loop!
I actually had found and tried .physicsBody.linearDamping on the spheres, but it didn’t work and that makes sense if it’s for a different class. I’m testing/adjusting linear and angular velocity, will get there eventually!

I was wondering about the felt… I peeked at the fur extension but it didn’t sound like physics could be applied to it. Even if not, though, it would probably give a cool look to the table.

Thanks for the welcome, I’m enjoying learning BJS and the forum has helped a lot.

1 Like