[Solved] Hinge constraint with sticky limits

Krones
Posts: 10
Joined: Tue Sep 22, 2009 4:46 pm

[Solved] Hinge constraint with sticky limits

Post by Krones »

Hi!

I'm developing a game using Bullet and I got somewhat stuck with constraints.
I have an object that I want to spin around an axis for which I've set a hinge constraint like the following:

Code: Select all

btHingeConstraint* hinge;
btVector3 btPivotA(0.0f, 0.0f, 0.0f);
btVector3 btAxisA(0.0f, 0.0f, 1.0f);
hinge = new btHingeConstraint(*body, btPivotA, btAxisA);
hinge->setLimit(lowerLimit, upperLimit);
dynamicsWorld->addConstraint(hinge);
And which I make it spin using:

Code: Select all

body->applyTorqueImpulse(btVector3(0, 0, -100));
As it is now, when torque impulse is applied and the object reaches the limit of the hinge constraint it "bounces" back and rotates on the opposite direction. What I'm trying to do is to have it stop at the limit of the hinge, only rotating back when a collision or another force is applied. How could that be done?

Thanks in advance
Last edited by Krones on Wed Sep 30, 2009 10:00 pm, edited 1 time in total.
fishboy82
Posts: 91
Joined: Wed Jun 10, 2009 4:01 am

Re: Hinge constraint with sticky limits

Post by fishboy82 »

This seems like the "over shoot" problem.Because the solver need to correct the error value that exceed the limit so this will introduce additional "angular impluse" which is as you said "Bounce back", or may be it is the bounce parameter that are no correctly setted
.
User avatar
rponomarev
Posts: 56
Joined: Sat Mar 08, 2008 12:37 am

Re: Hinge constraint with sticky limits

Post by rponomarev »

Hello,

You could adjust hinge parameters when you set limits.
The function setLimits has several default parameters :

Code: Select all

void	setLimit(btScalar low,btScalar high,btScalar _softness = 0.9f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f)
_softness used by obsolete version of solver and left for compatibility;
_biasFactor applied as a factor to constraint error
_relaxationFactor controls bounce (0.0 == no bounce)

So you could try something like:

Code: Select all

hinge->setLimit( lowerLimit, upperLimit, 0.9f, 0.01f, 0.0f);
Thanks,
Roman
Krones
Posts: 10
Joined: Tue Sep 22, 2009 4:46 pm

Solved!

Post by Krones »

Thanks a lot Roman, setting those as you suggested worked perfectly! :)
Krones