Search code examples
c++physics-enginebulletphysics

How do I set the position of a soft body in Bullet Physics


I'm trying to lock the movement of a soft body to the x axis. I want to be able to move left and right but lock it to the same position in the z axis.

Even when I am applying a velocity along the x axis it can sometimes cause the body to move back in the z axis due to air resistance and the way the soft body moves I assume.

To combat this problem I want to use a tick callback to make sure that the soft body's z position is always 0;

Is this the best way to go about it, and if so how do I set the position.

I have tried .transform() and .translate() but have not managed to get it working.

Thanks.


Solution

  • Try using the setLinearFactor() code. It works like that:

    body->setLinearFactor(btVector3(0.0, 1.0, 1.0));
    

    This code blocks any movement on the x axis. the body structure can be a rigidbody or a softbody and the btVector3 parameters are: 1 for movement and 0 to block any type of movement. In your case it would look like I did before