turning on and off one constraint

Post Reply
CarinaCruz
Posts: 21
Joined: Wed Mar 25, 2015 2:04 pm

turning on and off one constraint

Post by CarinaCruz »

Hello everyone!

I am trying enabling and disabling a constraint so that I can enable it when a collision happens and disable it when the collision ends.

what better way to do this ?

I'm trying something like this:

if(colisao){ //creates a constraint

sphete.getBasis().setEulerZYX(0, SIMD_HALF_PI, 0);
palma.setOrigin(btVector3(0, 20, 12));
joitn6DOF = new btGeneric6DofConstraint(*bodySphere, *bodyPalma, sphere, palma, false);
world->addConstraint(join6DOF, true);

}else{ //When the collision ends

/* Delete constraint */

}

But the sphere and the hand do not been together when the collision happens. The sphere is spinning all the time and the constraint does not work...

Please someone helps me!

Thanks!
:roll: :roll: :roll: :roll: :roll: :roll:
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: turning on and off one constraint

Post by Basroil »

Did you remember to set constraint limits/ motors?
CarinaCruz
Posts: 21
Joined: Wed Mar 25, 2015 2:04 pm

Re: turning on and off one constraint

Post by CarinaCruz »

Yes basroil, I added the limits... I can add a constraint at the moment that collision happens, but when the collision ends the constraint isn't removed...
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: turning on and off one constraint

Post by Erwin Coumans »

Did you use world->removeConstraint(...) ?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: turning on and off one constraint

Post by Basroil »

CarinaCruz wrote:Yes basroil, I added the limits... I can add a constraint at the moment that collision happens, but when the collision ends the constraint isn't removed...
In that case the code you posted isn't being clear about what you're actual code is doing. As Erwin said, if you want to remove the old constraint you'll need to explicitly remove it from the world, but none of that code was in your original comment.
Post Reply