Moving an obstacle along a fixed path

cbuchner1
Posts: 17
Joined: Fri Apr 10, 2009 6:44 pm

Moving an obstacle along a fixed path

Post by cbuchner1 »

Hi,

The following is a "newbie" question. I have limited experience with the bullet library so far. I am trying to implement this coin pusher prototype game and I've hit a snag.

The mechanical pusher is modelled as a btBoxShape in Bullet - I plan to move it along a predetermined path in a forward-backward motion, such that it pushes coins towards the player. Also coins that fall on top of the pusher are supposed to be moving with the pusher due to surface friction.

My first approach was to simply constantly set the position of the pusher within the physics loop using

Code: Select all

btTransform trans;
trans.setIdentity();
trans.setOrigin(pos);   // <-- pos is a btVector3 containing the current x,y,z coordinates of the pusher
psh->setWorldTransform(trans)
However this failed miserably - apparently the coins decide to ignore the new pusher location and just acted as if the position never changed. Did I miss anything here?

Another problem with this approach is (assuming that it worked) that the pusher would instantly change its location and any coin resting on top of it would stay at its place, rather than move along due to friction.

So how would I do this properly? If I give the pusher a mass and exert a force on the pusher, it might start to rotate when some coins bounce into it. Also if I tried to move the pusher forward and backward by applying a force or impulse to it, it will move but not necessarily in a very controlled way. I need it to follow a pretty precise sinusoidal motion along one coordinate axis. Much like a moving platform in a jump and run game.

BTW, The technical details about my physics assumptions are summarized in this thread - it also contains some unanswered questions. http://www.bulletphysics.org/Bullet/php ... &f=&t=3623

I am starting to believe that axis aligned bounding boxes are pretty inefficient with thin coins. They produce too many candidates during the broad phase collision detection. The simulation grinds to a halt at less than 100 coins. I might have to roll my own code here.

Christian
cbuchner1
Posts: 17
Joined: Fri Apr 10, 2009 6:44 pm

Re: Moving an obstacle along a fixed path

Post by cbuchner1 »

Solved it!

Apparently you need to do psh->GetMotionState()->setWorldTransform(); on a kinetic object to change its position
as opposed to just psh->setWorldTransform().

Doing this in the main loop had several nasty side effects. The physics main loop runs in the (sometimes very low) frame rate of the graphics card, so the coins would sometimes penetrate the pusher deeply when the pusher got translated. This resulted in the coins experiencing large accelerations away from the pusher during contact resolution (flying away instead of getting pushed out of the way). Also coins falling on top of the pusher did not move along with it and eventually fell off.

I solved this by making the pusher not a Kinetic object but a dynamic object with a mass (say, 1 kg which is huge compared to the coin mass). I also set the Angular Factor to 0, preventing rotation of the pusher. Instead of translating the pusher with setWorldTransform() I now update the pusher with a linear speed component that is proportional to the vector from the pusher's current position to the intended position (a sinusoidal motion forward and backward). Also I perform this update in the DynamicsWorld Tick callback (200 times per second). So now the interpenetrations with the coins are tiny and they are smoothly pushed forward, instead of being flung away.

Problem solved.

I still have issues with scalability. Above 60 coins the performance just crashes.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Moving an obstacle along a fixed path

Post by Erwin Coumans »

Simulating 0.005 meter objects is difficult with Bullet and it will require careful tweaking. Here some hints:
  • Only meter units are supported, along with a gravity around 10m/s^2. So please don't use millimeters, it causes the slide/jitter effect, and might degrade performance a lot.
  • Are you using an optimized build (-O2)? If not, please do so.
  • What arguments are you passing into 'stepSimulation'? Passing in 0 as second argument, or a variable value as third argument are not supported.
  • Note that the default collision margin is around 0.04 (4 centimeter), so you might want to set it to a lower value for the coins.
  • What collision geometry are you using for the static geometry?
Can you build a simple prototype in a Bullet demo, and share the (zipped) code in this forum, so others can look at it?
Thanks,
Erwin