Grooved joint giving inconsistent results

Official forum for the Chipmunk2D Physics Library.
Post Reply
earltedly
Posts: 4
Joined: Mon Feb 07, 2011 11:30 am
Contact:

Grooved joint giving inconsistent results

Post 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 :)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Grooved joint giving inconsistent results

Post by slembcke »

I think you have your bodies backwards. The "groove" is on bodyA and the pin is on bodyB.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
earltedly
Posts: 4
Joined: Mon Feb 07, 2011 11:30 am
Contact:

Re: Grooved joint giving inconsistent results

Post 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?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Grooved joint giving inconsistent results

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
earltedly
Posts: 4
Joined: Mon Feb 07, 2011 11:30 am
Contact:

Re: Grooved joint giving inconsistent results

Post by earltedly »

I'll have a look and see if I can get it to run.
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests