Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I realistically model a golf stroke with Bullet physics? (Live demo included)

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

like image 230
Peter de Rivaz Avatar asked Aug 29 '13 18:08

Peter de Rivaz


1 Answers

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);
like image 129
Timothy Shields Avatar answered Sep 21 '22 16:09

Timothy Shields