Hinge joints

Sep 29, 2009 at 7:41 PM

Hi! First of all, congratulations on a project well done, it's a rare pleasure to see such beautifully written code.

Now, since I'm new to Oops!, I was wondering if there is a quick and easy way to get a hinge constraint: a joint that rotates in only one dimension, like a knee or elbow, as opposed to a two- or three-dimensional joint like a shoulder/wrist/neck. I already saw the PointToPointConstraint but I can't think of a way to restrict its rotation. Perhaps I should implement my own Constraint-derived class? Has anyone thought about this already?



Oct 1, 2009 at 1:25 AM

Hi Orlin, thanks for the kind words.  You can create an unrestricted hinge with two PointToPointConstraint instances constrained to the two same rigid bodies separated enough to prevent twisting action but restricting the pendulum effect (elbow going backwards) would need to be handled differently.  If you have the know-how, A derived Constraint class to mimic a hinge is indeed your best bet.  Good luck!

Oct 1, 2009 at 7:31 AM

Thank you for your timely response! My math is a little rusty but I'll give it a try :)

Oct 1, 2009 at 3:27 PM

Ok, I managed to do it without deriving from Constraint. That might be of help to someone so here's my solution: first I used two PointToPointConstraints at either side of the elbow to restrict it from rotating sideways, as was fretboardoffury's idea. Then I added two small CollisionBoxes at the back side of the elbow, one just below and one just above it. So when the arm is straight, the two CollisionBoxes collide and stop the elbow from going backwards. The two CollisionBoxes could even be invisible so the player won't notice a thing. I know it's a dirty little hack but it works like a charm and saved me the trouble of doing all that math

Oct 2, 2009 at 3:04 AM

That is genius!!!