How to create a yardstick behaviour?

How would I go about creating a yardstick behaviour?

Like, if I have a stick divided into three sections, meaning it has four “control points”; one at each end of the stick and one at 1/3 of the length of the stick and another at 2/3 of the length of the stick.

I should be able to rotate around each of these points and the rest of the stick should rotate accordingly, like a parent-child setup. I also want the points to rotate when we “stretch out” the stick.

For example:
Stick is completely straight, going from left to right with the first control point at the left end. I rotate 45 degrees around the second control point. If I now grab the third control point and pull straight to the right the stick is supposed to straighten out again, until it is as straight as possible, at which point I cannot pull any more.

I hope my textual description is visual enough to make it clear what kind of behaviour I’m trying to achieve. I pretty much want it to work exactly like a yardstick with “anchor points” at the ends of stick.

You seem to have answered your own question right there (i.e., use parent-child).

–Eric

That works fine for rotating, but doesn’t work at all when it comes to moving any of the child objects. The parents will be left behind, not to mention “stretch out” accordingly.

I’ve tried playing around with joints a bit, but without any luck.

have each part of the stick parented to another and so forth down the line.

stick1

  • stick2
    ** stick3
    *** stick4

then add each to a array of sticks

then go though each stick in the array and move/rotate how you want

for (int i = 0; i < array.count; i++)
{
 //move and rotate arraystick[i]
}

since they are parented you just go down the line and move each a little bit and it will move the child sticks.

10 sticks each moved 1meter = a 10meter long yardstick.

You talk about pulling/stretch the points.
So if you grabbed the last child in the chain and moved it, the yardstick would straighten out?

If so, that would require some sort of IK (Inverse Kinematic) solver. I’d play around with HingeJoint, but I’ve only done IK in Havok, so not sure about PhysX.

Exactly. And if the yardstick is fully straight, it wouldn’t be able to be move anymore in that direction. The user would still be able to rotate it all by moving that last child and moving it in a circular motion (once the yardstick is fully stretched).

I’ll look it up and see if I can manage to understand how that works. It’s all new to me, but it feels as though using some kind of physics system for this should be the right way to go.