3

I have a problem that I'm strugling to solve for a few days.

I'm trying to make a bowling game using bullet physics, but the pin shakes, jiggles and moves to the side after I position it and it falls to the floor.

Here is a GIF of what happens: https://i.stack.imgur.com/mj5ex.jpg

Here is how I create a Pin:

btCollisionShape* shape = createShape(pinVertices);
btScalar bodyMass = 1.6f;
btVector3 bodyInertia(0,0,0);
shape->calculateLocalInertia(bodyMass, bodyInertia);

btRigidBody::btRigidBodyConstructionInfo bodyCI = btRigidBody::btRigidBodyConstructionInfo(bodyMass, nullptr, shape, bodyInertia);
bodyCI.m_restitution = 0.7;
bodyCI.m_friction = 0.9f;

_physicsBody = std::unique_ptr<btRigidBody>(new btRigidBody(bodyCI));
_physicsBody->setUserPointer(this);

And here is how I create a floor:

btCollisionShape* shape = createShape(laneVertices);
btScalar bodyMass = 0.0f;
btVector3 bodyInertia(0,0,0);
shape->calculateLocalInertia(bodyMass, bodyInertia);

btRigidBody::btRigidBodyConstructionInfo bodyCI = btRigidBody::btRigidBodyConstructionInfo(bodyMass, nullptr, shape, bodyInertia);
bodyCI.m_restitution = 0.6;
bodyCI.m_friction = 0.5;

_physicsBody = std::unique_ptr<btRigidBody>(new btRigidBody(bodyCI));
_physicsBody->setUserPointer(this);

Right now the floor is a btBoxShape and a pin is a btConvexHullShape, but I've tried using cylinder or cone and they also slide.

Been struggling for few days especially taking into account Bullet Physics website and forum are down.

2 Answers2

2

Looks entirely reasonable to me. A rigid body isn't exactly going to bounce back up, nor is it going to shatter.

You have further issues with the imperfect approximation of reality. The bottom of your pin is probably flat, which means it theoretically hits the floor instantly over multiple points. Furthermore, due to the limited FP accuracy, the pin won't be exactly round, but then that part is realistic.

So the horizontal movements are probably because the small bit of freefall introduced a minor deviation from pure vertical fall. When hitting the ground this component wasn't cancelled, but the friction on moving did eventually bring the pin to a halt. Since the pin had only a small horizontal speed, the friction was not enough to topple the pin.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Thanks for the answer. What would you suggest to do to overcome this? The answer proposed by @user3155109 works, and maybe this is the way to go (deactivate all objects until they are hit by something if you want them to be at exact position where you set them). However, maybe there is another option? Best practice? – user3652475 May 19 '14 at 15:54
  • Deactivation is a 'core' function of Bullet to optimize speed. I think it is fair to use it in this case. – yombo Jun 04 '14 at 10:25
1

Perhaps you should set the restitution (bounce) of the pin and floor to something lower (try first with 0.0) This should solve it if the pin is bouncing.

Another thing you could try is to deactivate the pin after creating it. I don't know in Bullet, but in JBullet it's done like this:

body.setActivationState( CollisionObject.WANTS_DEACTIVATION );

This will stop your pin until some other object like the ball or other pin hits it.

yombo
  • 334
  • 2
  • 5
  • Thanks, the trick with deactivating the body seems to work. Also some issues was caused by instability of Bullet on 64-bit architecture, everything works much nicer on iPhone 4 simulator than on iPhone 4 (64-bit) simulator. – user3652475 May 19 '14 at 15:56