Grid-aligned Crates

Post Reply
User avatar
nikki
Posts: 22
Joined: Sat Jun 14, 2008 3:38 pm
Location: Doha, Qatar.
Contact:

Grid-aligned Crates

Post 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.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Grid-aligned Crates

Post 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);
Post Reply