Page 1 of 1

Grid-aligned Crates

Posted: Tue Aug 18, 2009 10:38 am
by nikki
Hey guys!

I'm working on a game where there are Crates (boxes) and the Player should be able to push them around. However, they must be aligned to grid in XZ plane (move only by one unit, either on X or Z axis), but free to move in Y (gravity,slopes). This is for Sokoban style puzzles. The rest of the world is 'proper physics' though.

How could I acheive this? I already tried having a vertical slider attached to a kinematic object, but that didn't work perfectly, and I think there are better ways to do it so I decided to ask here.

Re: Grid-aligned Crates

Posted: Tue Aug 18, 2009 2:05 pm
by Erwin Coumans
You might want to experiment with the 'angular factor', and use the latest version of Bullet 2.75:

Code: Select all

//no rotation
body->setAngularFactor(btVector3(0,0,0));
Hope this helps,
Erwin

In a similar way you can also limit translation along some axis using 'setLinearFactor'. For example the following only allows motion along the XZ axis:

Code: Select all

///prevent motion in the Y direction
body->setLinearFactor(btVector3(1,0,1);