7

Background

I am playing with making a minigolf game using three.js and the ammo.js conversion of the Bullet Physics library but I am having some trouble getting the ball to move realistically.

(I've put a demo at penguinspuzzle.appspot.com/minigolf.html if you want to have a look at how this works in practice.)

Question

What is a good algorithm to give more realistic motion of a minigolf ball?

What I've tried

In ammo.js there are options for friction, linear damping, and rotational damping.

As the ball rolls, the friction setting does not seem to have much effect.

I'm currently using

body.setRestitution(0.8);
body.setFriction(1);
body.setDamping(0.2,0.1); // linear damping, rotational damping

Problems

With high values of linear damping the ball seems to decelerate too fast.

With lower values it seems to take ages to finally stop.

When the ball is in the air it seems unreasonable to be applying linear damping at all.

Analysis

I think the problem may be the linear damping in ammo.js which causes an exponential slow down.

I tried:

  1. Recording a video of a golf stroke
  2. Measuring the location of the ball in each frame
  3. Plotting the location and speed of the ball against time

The results are shown below. It looks to me like the velocity profile is much closer to being linear than exponential.

Any suggestions for an algorithm to get ammo.js to be more realistic?

Golf analysis

Timothy Shields
  • 75,459
  • 18
  • 120
  • 173
Peter de Rivaz
  • 33,126
  • 4
  • 46
  • 75

1 Answers1

2

I spotted that you're using "regular" friction on a spherical object. In physics there is a separate concept, "rolling friction" for round objects. I don't know whether Bullet Physics supplies such a concept in its API. If it does, try replacing this with the rolling friction counterpart:

body.setFriction(1);
Timothy Shields
  • 75,459
  • 18
  • 120
  • 173
  • I was thinking that's what is meant by "rotational damping". – Teepeemm Aug 29 '13 at 19:00
  • @Teepeemm Damping only has a real-world meaning when it comes to oscillatory spring-like systems. The "linear damping" and "rotational damping" concepts present in most physics engines do *not* have real-world meanings. They're there both for inserting slightly-fake physics into a game when a simple approximation will suffice and for maintaining stability in the physics simulation. Rolling friction and rotational damping are very much **not** the same thing. – Timothy Shields Aug 29 '13 at 19:03
  • Thanks, that is very useful - a constant force should give me the constant deceleration I was after. Strangely, there does seem to be a setRollingFriction in the Bullet physics C++ API, but as far as I can see it does not appear in ammo.js (and gives an undefined error when I try to use it). – Peter de Rivaz Aug 29 '13 at 19:40
  • 1
    @PeterdeRivaz You could always just compute the rolling friction force yourself. Basically, you want to apply a friction force to the ball, **but at the point where it contacts the ground, not the center of mass.** Likewise, when the ball stops bouncing and is in continuous contact with the ground, the speed of the ball should be the speed of the point on the ball which is in contact with the ground. What you end up with is that the rotational friction is reducing **both** the angular and linear momentum of the ball. – Timothy Shields Aug 29 '13 at 19:53
  • I can see that working - I definitely have the ability to apply forces at non-central locations and I can access the velocity so I know which direction to apply the force. If no-one knows why setRollingFriction is missing from ammo.js I'll try it with the force instead - thanks again! – Peter de Rivaz Aug 29 '13 at 20:09
  • @PeterdeRivaz I've seen it working. ;) I made a pool/billiards game before with ultra-realistic physics with a from-scratch physics engine and the approach I'm describing is what I used. It's the closest to how the forces are in the real world: impulse from golf club, impulse from bouncing off ground/objects, air friction, rolling friction (point of contact with ground). In general, if you're going for realistic physics, all forces and impulses should be applied at the location where they're actually applied - not the center of mass. – Timothy Shields Aug 29 '13 at 20:12