Page 1 of 1

turning on and off one constraint

Posted: Thu Jun 11, 2015 5:50 pm
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:

Re: turning on and off one constraint

Posted: Thu Jun 11, 2015 9:49 pm
by Basroil
Did you remember to set constraint limits/ motors?

Re: turning on and off one constraint

Posted: Mon Jun 15, 2015 12:55 pm
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...

Re: turning on and off one constraint

Posted: Mon Jun 15, 2015 7:16 pm
by Erwin Coumans
Did you use world->removeConstraint(...) ?

Re: turning on and off one constraint

Posted: Tue Jun 16, 2015 5:25 am
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.