[help][bge] set bone location

Another tread solved Thanks all!

i not think you had solved with my code (maybe with the flag “connected” ? ;))
the code posted above work only in some circumstance (if not there rotations)
asically is bugged
for someone interessed to the argument, this is surely more near to correct: (anyway still too complex)





import bge
from mathutils import Matrix, Quaternion, Euler, Vector
import random


def up(cont):
    arm = cont.owner
    bone = arm.channels["Bone.002"]
    target = arm.scene.objects["Cone"]
    
    m4_in_arm = arm.worldTransform.inverted() * target.worldTransform
    
    
    ################################## remove (or should) the offset of the bone
    q_offset = Quaternion(bone.rotation_quaternion)
    p_offset = Vector(bone.location)
    m4_offset = q_offset.to_matrix().to_4x4()
    m4_offset.translation = p_offset
    offset_inv = m4_offset.inverted()
    bone_pose_matrix_without_offset = bone.pose_matrix * offset_inv
    ##################################
    
    
    m4tbone = bone_pose_matrix_without_offset.inverted() * m4_in_arm
    
    p,q,s = m4tbone.decompose()
    bone.location = p # copy the position of the target 
    bone.rotation_quaternion = q # copy the rotation of the target
    arm.update()