23.9 C
New York
Monday, April 28, 2025

How do I join a goal utilizing Skeletonmodifier3D of Godot?


I’ve been making an attempt to study extra about Skeletonmodifier3D of Godot and I’m beginning with a easy characteristic: I desire a bone that factors in a node3d. I attempted to comply with this official information: https://godotengine.org/article/design-of-the-skeleton-modifier-3d/
However the code within the article didn’t work. I couldn’t perceive if there’s a logic, however the bone merely doesn’t level to the objective, he factors out in numerous instructions. (The distinction between the bone of the article and that of my sport that in my sport is a part of a hierarchy of bones (it’s the bone of the arm)))))))

I attempted one thing that I believed can be easy, based mostly on the article and a few investigations:

func _process_modification() -> void:
    var skeleton: Skeleton3D = get_skeleton()
    if not skeleton or not target_node:
        return
    
    var bone_idx: int = skeleton.find_bone(upper_arm_bone)
    var bone_pose: Transform3D = skeleton.get_bone_global_pose(bone_idx)
    var pose: Transform3D = skeleton.global_transform * bone_pose
    var looked_at: Transform3D = pose.looking_at(target_node.global_position, Vector3.UP, true)

    DebugDraw3D.draw_box_xf(looked_at, Shade.YELLOW)
    
    skeleton.set_bone_global_pose(bone_idx, Transform3D(looked_at.foundation.orthonormalized(), skeleton.get_bone_global_pose(bone_idx).origin))

    DebugDraw3D.draw_box_xf(skeleton.global_transform * skeleton.get_bone_global_pose(bone_idx), Shade.PURPLE)

However observe the mismatch between the 2 transformations:

From what I perceive, the road Transform3D(looked_at.foundation.orthonormalized(), skeleton.get_bone_global_pose(bone_idx).origin) It ought to create a brand new transformation with the identical rotation as look_at however within the place of the unique bone. The 2 purification views needs to be the identical, proper? Contemplating the transformations that apply.

Am I lacking one thing?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles