Page 1 of 1

Custom Joints

Posted: Tue May 21, 2013 3:01 pm
by Zamaster
Actually didn't find anything about this on the forum. Sooo, is this a thing? In particular I'm interested in coding a rail joint which needs to be a weird hybrid of semi-circular sections and straight lines. By rail I mean that an anchor point is confined to a pre-defined "rail" (think roller coaster). This is for some wall climbing type code.

Anyway, is there any documented way to create a custom joint, or at least some specifications? Thanks!

Re: Custom Joints

Posted: Tue May 21, 2013 3:04 pm
by Zamaster
I should add the rail itself is the joint and the anchor points are from the one object to which the rail is fixed and the other which is fixed to the rail. Hopefully this could be facillitated by chipmunk somehow.

Re: Custom Joints

Posted: Tue May 21, 2013 3:43 pm
by slembcke
So other than the code of the existing joints there isn't really any documentation on how it all works. Sounds like you want something that is a hybrid of the groove and pin joints though. Since you'll need to be switching between different joint modes anyway, you can probably get away with actually switching joints. Detect which section of the track you are on and activate that joint.

Better custom joint support is something I really want to tackle for Chipmunk 7, but that's a ways off.

Re: Custom Joints

Posted: Tue May 21, 2013 5:57 pm
by Zamaster
Good idea! Much better to use whats there than reinvent the wheel. Thanks.

Re: Custom Joints

Posted: Tue May 21, 2013 6:08 pm
by Zamaster
I suppose my other question is whether or not there is some way mid step to sort of stop, hammer time and switch joints, then resume the step? I suppose this could be done with some flavor of callbacks, but I feel like theres a good way and an uninformed way to do it and I'll probably end up doing it the uninformed way.

Re: Custom Joints

Posted: Wed May 22, 2013 9:17 am
by offonoff
Why would you need to do this mid step? I (a noob) would think you would use a collision handler to determine when the object needs to switch rails, and set a post step callback to remove one joint and add another.

Re: Custom Joints

Posted: Wed May 22, 2013 9:22 am
by slembcke
Well, since the rail parts aren't actually collision shapes, I'm not sure how that would help you really. I'd just do it outside of the timestep completely.

Re: Custom Joints

Posted: Wed May 22, 2013 12:25 pm
by Zamaster
I was more or less thinking about an object moving over a rail, if things weren't handled during the step, the object might stop moving at the groove joint endpoints. If there were some way to switch joint types at certain endpoint conditions (hit an end of the groove / reached a certain realative angle of a pin joint) either mid step, OR, stop the simulation at such a condition without applying impulses -> disconnect+reconnect some joints -> continue the simulation.

Re: Custom Joints

Posted: Wed May 22, 2013 1:02 pm
by slembcke
Just set up the groove joints to extend beyond the straight segments of your track. No need to be super exact.