I’m really sorry to have to ask, since I’m new, but I’m having trouble with attaching a geometry to a bone so that it does not have an offset from this bone.
This is my code, to attach a cube (a box geometry) to the bone, which is the head of my robot arm:
cube.setLocalTranslation(head.getWorldTranslation()); cube.removeFromParent(); head.attachChild(cube);
What happens, is that the cube attaches itself to the head, but with a very slight offset. I can then animate the robot arm and the cube goes with the head perfectly. Afterwards, the cube is set down by the robot arm and I attach it to the rootNode:
Vector3f position = cube.getWorldTranslation(); cube.removeFromParent(); rootNode.attachChild(cube); cube.setLocalTranslation(position);
I can move the arm again, without moving the cube. So far so good… I animate the arm, so that it is back in it’s original position.
But then I want to reset the cube to it’s original location (before the animation) and start the process all over again. Here the problem arises, that the offset of the cube (when attached to the head) suddenly is huge. So the cube is floating in the air. I try to reset the cube with
but it doesn’t change its location at all.
What I don’t understand is why it behaves like that in the second round of animation.
Does anyone know, how to correctly attach geometries to bones, so that there is no offset?
Thanks in advance!