I have an object inside a bone, matches the bone exactly (position, scale, rotation). The armature and the object have different origin points.

I am trying to make the object follow the bone exactly when i change its position - rotation using python.

I am guessing my math is wrong (works if the object has 0,0,0 as original position )

enter image description here

And here is the code and the file so it will be easier to prototype

from mathutils import Matrix
import bpy

ob = bpy.context.active_pose_bone
obj = ob.id_data

T =  Matrix.Translation(1* (ob.tail - ob.head))
matrix_final = obj.matrix_world @ (T@ ob.matrix_channel)

obj2 = bpy.data.objects["Bone.001|Armature"]
obj2.matrix_world = matrix_final



1 Answer 1


Couple of possible issues;

  1. It looks like you've rigged this in an odd way... basically bones need to be aligned to meshes in EDIT MODE not 'posed' into position in POSE MODE, if that's done there's a coordinate mismatch between the two if the bone is reset.

  2. Ideally you want to make sure both objects ORIGIN's are in the same location with Rotation, Location & Scale fixed - coordinates are all relative.

  3. Instead of (1* (ob.tail - ob.head)) try (0* (ob.tail - ob.head)); using "1" is offsetting the mesh along the bones Z axis so it roots to the tail bone node.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .