Page 1 of 1

Grooved joint giving inconsistent results

Posted: Fri Jul 22, 2011 10:20 am
by earltedly
I have a situation at the moment where I have two bodies, A & B.

A is a static body
B is a moving body being dragged around
P is a fixed position directly below A

When B hits A, I wish it to slide to P and stay there at exactly that spot.

Currently I'm implementing a collision handler between A & B which (after the step has completed) puts a GrooveJoint between the current position of B and position P with an anchor of zero.

About 80% of the time B correctly arrives at point P.
The other 10% B ends up offset either to the left, right or below...

I've looked a the velocity each time to see if going over a certain threshold appears to cause the problem, but it's pretty random.

I've tried putting a damped spring between B & P as well, but to no avail. I was wondering if anyone has any ideas of firstly what is going on, and secondly what I can do to fix it?

Code: Select all

CGPoint start = ccpSub(bodyB.pos, bodyA.pos);
CGPoint P = CGPointMake(0, -50);
ChipmunkGrooveJoint* grooveJoint = [ChipmunkGrooveJoint grooveJointWithBodyA:bodyB bodyB:bodyA groove_a:start groove_b:P anchr2:CGPointZero];
[space add:grooveJoint];
Thanks in advance for replies :)

Re: Grooved joint giving inconsistent results

Posted: Fri Jul 22, 2011 12:06 pm
by slembcke
I think you have your bodies backwards. The "groove" is on bodyA and the pin is on bodyB.

Re: Grooved joint giving inconsistent results

Posted: Mon Jul 25, 2011 3:49 am
by earltedly
Thanks for the reply.

Yep - definitely backwards! Thanks for pointing that out :)

Unfortunately, I'm still getting the same problem, although a bit more consistently now.

Half the time, the body will come to rest too high, the other half too low, with some variation left and right.

Generally the higher the velocity when the joint is applied, the greater the error factor. I presume this is due to the joint not being able to correct things fast enough.

Is there a way I can tweak the maxForce, maxBias, and biasCoef to increase their powers of correction?

Re: Grooved joint giving inconsistent results

Posted: Mon Jul 25, 2011 8:33 am
by slembcke
Hmm. Is it possible to run the debug drawing code I have alongside your own graphics? That might help debug the problem by showing you exactly what the physics are trying to do. I'm not I understand exactly what the problem is without a picture and am not sure what advice to give you.

Re: Grooved joint giving inconsistent results

Posted: Mon Jul 25, 2011 9:04 am
by earltedly
I'll have a look and see if I can get it to run.