From cc4dc1e5a8e2df3357a5190136213f11b974f789 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 24 Mar 2022 10:43:53 +0100 Subject: [PATCH] Backported: Fix create skeleton bone position - Blackiris - https://github.com/godotengine/godot/commit/480543f681b50c3037f161bd0ecd531e78b87912 --- .../skeleton_editor/skeleton_editor_plugin.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/skeleton_editor/skeleton_editor_plugin.cpp b/modules/skeleton_editor/skeleton_editor_plugin.cpp index 04d821715..81a299f7b 100644 --- a/modules/skeleton_editor/skeleton_editor_plugin.cpp +++ b/modules/skeleton_editor/skeleton_editor_plugin.cpp @@ -620,7 +620,9 @@ void ModuleSkeletonEditor::create_physical_skeleton() { } PhysicalBone *ModuleSkeletonEditor::create_physical_bone(int bone_id, int bone_child_id, const Vector &bones_infos) { - real_t half_height(skeleton->get_bone_rest(bone_child_id).origin.length() * 0.5); + const Transform child_rest = skeleton->get_bone_rest(bone_child_id); + + real_t half_height(child_rest.origin.length() * 0.5); real_t radius(half_height * 0.2); CapsuleShape *bone_shape_capsule = memnew(CapsuleShape); @@ -630,8 +632,17 @@ PhysicalBone *ModuleSkeletonEditor::create_physical_bone(int bone_id, int bone_c CollisionShape *bone_shape = memnew(CollisionShape); bone_shape->set_shape(bone_shape_capsule); + Transform capsule_transform; + bone_shape->set_transform(capsule_transform); + + Vector3 up = Vector3(0, 1, 0); + if (up.cross(child_rest.origin).is_equal_approx(Vector3())) { + up = Vector3(0, 0, 1); + } + Transform body_transform; - body_transform.origin = Vector3(0, 0, -half_height); + body_transform.set_look_at(Vector3(0, 0, 0), child_rest.origin, up); + body_transform.origin = body_transform.basis.xform(Vector3(0, 0, -half_height)); Transform joint_transform; joint_transform.origin = Vector3(0, 0, half_height);