Moving Kinematic platform applies friction multiple times

tomhog
Posts: 6
Joined: Mon Jul 04, 2011 4:37 pm

Moving Kinematic platform applies friction multiple times

Post by tomhog »

Hi All

This is my first post here, I did a quick search on the forum and couldn't find exactly this issue although moving kinematic objects and scaling to cm's do seem to come up a bit. I've only been using Bullet for around 2 weeks so bear with me if I'm missing something obvious.

I'm making a tin can shooter game, I decided to use cm as my units as I needed quite a small bullet to shoot the cans.

I successfully got a stack of cans working as dynamic rigid bodies standing on a static box. Shooting them works but I did have to increase the step time resolution as I was getting bouncing from the cans penetrating due to gravity and sometimes the bullet was tunnelling through the cans, my step function looks like this

_dynamicsWorld->stepSimulation(stepTime, 4, 1.0f/240.0f);

The step time is in seconds and everything seemed groovy, the bouncing/jitter went away an and my tunnelling was mostly gone.

Enter the moving platform,

This was done by setting up the same scene but instead of a standard static box to stand the cans on, I made the box kinematic

boxBody->setCollisionFlags( boxBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
boxBody->setActivationState( DISABLE_DEACTIVATION );

And used a motionstate to manually move the box

osgbBullet::MotionState * motion = new osgbBullet::MotionState();
motion->setTransform( box );
motion->setParentTransform( osg::Matrix::translate( center ) );

btScalar mass( 0.0 );
btVector3 inertia( 0, 0, 0 );
btRigidBody::btRigidBodyConstructionInfo rb( mass, motion, collision, inertia );
rb.m_linearSleepingThreshold = rb.m_linearSleepingThreshold * osgBulletUtils::getScaleFactor();
btRigidBody * body = new btRigidBody( rb );

As you can see from the above I am using osgBullet I'm also using Bullet version 2.75.

The problem is that when the platform moves, the can (i made it just one in the end), seems to move 3/4 times the distance. As if not only is the platform moving but it also has a conveyor belt on it. So once the platform moves a small distance the can has slid to the end (same end as direction the platform is moving), and fallen off.

It seemed very odd to me and at first I thought that perhaps it was an issue with osgBullet, but I've asked on their forum and it seems it is a Bullet issue as the motionstate is used to move the platform (my osgBullet post below)

http://groups.google.com/group/osgbulle ... 3fc70fcb3e

After the above conversation I've done a little more investigation and have now found the cause but not how to fix it. Strangely enough if I made the cans a little bigger so they didn't suffer the bouncing I was able to set the stepSimulation back to one iteration

_dynamicsWorld->stepSimulation(stepTime); //, 3, 1.0f/180.0f);

Once I did this the can on the moving platform behaves as expected (still goes funny with old steoSim), it's as if the full friction from sliding is being applied every sub iteration but only in one direction.

Here's a link to zip of the main files needed for my app, it's for IPhone but the only thing that needs looking at in MatchOsgViewController.m is the initBulletWorld and updateScene functions. Everything else bullet related is in the BulletUtils.h and cpp.
http://www.hogbox.co.uk/data/BulletTest.zip

Cheers
Tom

PS
I can only imagine scaling to cm might have caused this, but I also followed this guide for the scaling
http://www.bulletphysics.org/mediawiki- ... _The_World
tomhog
Posts: 6
Joined: Mon Jul 04, 2011 4:37 pm

Re: Moving Kinematic platform applies friction multiple time

Post by tomhog »

pretty please :)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Moving Kinematic platform applies friction multiple time

Post by Erwin Coumans »

I'll have a look and try to reproduce it. There could be an issue with substeps/kinematic objects.

Thanks for the report,
Erwin
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Moving Kinematic platform applies friction multiple time

Post by Erwin Coumans »

I created a similar test, and it works just fine using the most recent version of Bullet (2.78).

See attached BasicDemo.cpp. You can either update the worldtransform on the rigid body or on the world transform.
This update of the worldtransform should happen before calling the 'stepSimulation' and not during a simulation substep.

Which version of Bullet are you using?
Are you using an unmodified version of Bullet?
How and when do you update the world transform for the kinematic moving platform?

Can you compare your setup with attached BasicDemo.cpp?
Thanks,
Erwin
You do not have the required permissions to view the files attached to this post.
tomhog
Posts: 6
Joined: Mon Jul 04, 2011 4:37 pm

Re: Moving Kinematic platform applies friction multiple time

Post by tomhog »

Hi Erwin

Thanks for this, most helpful. I'm currently using an unmodified version 2.75.

To move the kinematic platform I have an animation callback for osg. During osgs update phase the callback is triggered and sets the position with the below code.

rb->getRigidBody()->getMotionState()->setWorldTransform(
osgbBullet::asBtTransform( mat ) );

Get Rigid body return a btRigidBody.

The osg update and render phase happen after the simStep, my update func looks like the following

//update physics
float currSimTime = _viewer->getFrameStamp()->getSimulationTime();
float timeMulti = 1.0f;
float stepTime = (currSimTime - _prevSimTime)*timeMulti;

//OSG_FATAL << "Step: " << stepTime << std::endl;
_dynamicsWorld->stepSimulation(stepTime, 7, 1.0f/400.0f);//, 5);// (currSimTime - _prevSimTime) * timeMulti );

_prevSimTime = currSimTime;

//update osg and draw frame
_viewer->frame();

The fixed timestep is just experimental, i've used all kinds of values now.

I'll take look at your code and If I still have no luck will try updating to 2.78,

Thanks again for this, it's much appreciated
Tom

PS
Once I'm done I'll write up a little guide to creating an IPhone project for bullet using CMake, worked pretty well for me
tomhog
Posts: 6
Joined: Mon Jul 04, 2011 4:37 pm

Re: Moving Kinematic platform applies friction multiple time

Post by tomhog »

Hi Again Erwin


So had a chance to test out your example code and indeed, it didn't work in 2.75 but did in 2.78. So I tried to build osgbullet using 2.78 but osgBullet had some issues.

In the end i tried 2.76 which worked and also worked with osgbullet.

So to summarise it seems the 2.75 tag has an issue with stacking dynamic object on top of kinematic object. 2.76 upward seem fine.

Thanks for the help with this, saved me a massive headache.
Tom

PS
Loving bullet