Apply force to a child in a btCompoundShape?

AngelGM
Posts: 12
Joined: Mon Oct 28, 2013 2:40 pm

Apply force to a child in a btCompoundShape?

Post by AngelGM »

Hi there,

I have a btCompoundShape with two child shapes. I want to apply a specific force to just one of the child shapes.
Is that possible? I'm new to Bullet and struggling with this.

At the moment I am just updating the position of that child shape to "simulate" the movement due to forces, but that is not a valid approach when collisions occur.

Very many thanks!!

A.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Apply force to a child in a btCompoundShape?

Post by Flix »

AngelGM wrote: I want to apply a specific force to just one of the child shapes.
Is that possible?
Nope, compound shapes have been designed mainly to simulate moving concave bodies (and they're commonly used to shift the rigid bodies' center of mass too).

Some people use them to attach/detach child shapes at runtime, but it's not a good practice to transform child shapes at runtime.

What you need to do if you've got a body made of two movable parts is to create two separate rigid bodies and connect them with constraints. Then you can apply forces or impulses to one of them if you like (although most people like to apply motors to the constraint itself). The simplest kind of constraint is the btFixedConstraint, although you should probably choose the right one according to the movement you need (and block it if needed). The btGenericDof6Constraint (or something like that :wink: ) is usually a good generic solution.

Alternatively if you just have two 'states' and you're not interested to the relative movement itself, you can build two compound shapes with the two states and switch between them at runtime (it's a good practice to remove the body from the world before changing its collision shape and then readd it).

One advantage of these approaches is that you can reuse the collision shapes for multiple bodies, because 'the relative movement' is not hardcoded into the collision shape itself.

P.S. You might find this post useful if you opt for the constraint solution http://bulletphysics.org/Bullet/phpBB3/ ... t+velocity.
AngelGM
Posts: 12
Joined: Mon Oct 28, 2013 2:40 pm

Re: Apply force to a child in a btCompoundShape?

Post by AngelGM »

Many thanks!

I am playing with the constraints now and they seem to produce the effect I was looking for.
Alternatively, I also tried with btMultiBody, but then I got some other problems like when I have to delete one of the shapes (I cannot identify it -?-), but I will post this separately.

Cheers!
A.