Controlling a Joint Procedurally

Sometimes one wishes to procedurally take control of a model’s joint. For example, if you wish to force a character model’s eyes to follow the mouse, you will need to procedurally take control of the neck and head. To achieve this, use control_joint().

NodePath dummy = model.attach_new_node("dummy");
if (bundle->control_joint("Joint Name", dummy)) {
  std::cerr << "Success!\n";
}

This creates a dummy node. Every frame, the transform is copied from the dummy node into the joint. By setting the transform of the dummy node, you can control the joint. Normally, one would want to use set_hpr() to rotate the joint without moving it. The dummy node is initialized in such a way that the joint is in its default location, the one specified in the model file.

You must store a local (not global) transform in the dummy node. In other words, the transform is relative to the joint’s parent bone. If you are controlling the forearm of a model, for instance, the transform will be relative to the upper arm.

To undo a previous control_joint() call, pass the name of the joint to the release_joint() method:

bundle->release_joint("Joint Name");