Skip to content

Commit

Permalink
Fix create skeleton bone position
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackiris committed Oct 23, 2021
1 parent 18aaa88 commit 480543f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions editor/plugins/skeleton_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ void SkeletonEditor::create_physical_skeleton() {
}

PhysicalBone *SkeletonEditor::create_physical_bone(int bone_id, int bone_child_id, const Vector<BoneInfo> &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);
Expand All @@ -108,11 +110,16 @@ PhysicalBone *SkeletonEditor::create_physical_bone(int bone_id, int bone_child_i
bone_shape->set_shape(bone_shape_capsule);

Transform capsule_transform;
capsule_transform.basis = Basis(Vector3(1, 0, 0), Vector3(0, 0, 1), Vector3(0, -1, 0));
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);
Expand Down

0 comments on commit 480543f

Please sign in to comment.