diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-08-18 08:55:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 08:55:40 +0200 |
commit | d67c5a8e82df7c2840efa1238b7f673027fe0282 (patch) | |
tree | d51ea2c36ca9e68708d6f872973b606ad9281db3 | |
parent | 17ce4846ff6d14464d87f62bd1ea05176eeaf6ca (diff) | |
parent | 2562a7d1df24fd12e80a605a40f9168c4121e369 (diff) |
Merge pull request #51820 from TwistedTwigleg/skeleton_modifier_fabrik_2d_magnet_fix
Fixed magnet vector not working correctly in SkeletonModification2DFABRIK
-rw-r--r-- | scene/resources/skeleton_modification_2d_fabrik.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/scene/resources/skeleton_modification_2d_fabrik.cpp b/scene/resources/skeleton_modification_2d_fabrik.cpp index c03a92b503..6e9429034f 100644 --- a/scene/resources/skeleton_modification_2d_fabrik.cpp +++ b/scene/resources/skeleton_modification_2d_fabrik.cpp @@ -149,15 +149,6 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) { return; } fabrik_transform_chain.write[i] = joint_bone2d_node->get_global_transform(); - - // Apply magnet positions - if (i == 0) { - continue; // The origin cannot use a magnet position! - } else { - Transform2D joint_trans = fabrik_transform_chain[i]; - joint_trans.set_origin(joint_trans.get_origin() + fabrik_data_chain[i].magnet_position); - fabrik_transform_chain.write[i] = joint_trans; - } } Bone2D *final_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[fabrik_data_chain.size() - 1].bone2d_node_cache)); @@ -223,6 +214,11 @@ void SkeletonModification2DFABRIK::chain_backwards() { Bone2D *final_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[final_joint_index].bone2d_node_cache)); Transform2D final_bone2d_trans = fabrik_transform_chain[final_joint_index]; + // Apply magnet position + if (final_joint_index != 0) { + final_bone2d_trans.set_origin(final_bone2d_trans.get_origin() + fabrik_data_chain[final_joint_index].magnet_position); + } + // Set the rotation of the tip bone final_bone2d_trans = final_bone2d_trans.looking_at(target_global_pose.get_origin()); @@ -245,6 +241,11 @@ void SkeletonModification2DFABRIK::chain_backwards() { Bone2D *current_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache)); Transform2D current_pose = fabrik_transform_chain[i]; + // Apply magnet position + if (i != 0) { + current_pose.set_origin(current_pose.get_origin() + fabrik_data_chain[i].magnet_position); + } + float current_bone2d_node_length = current_bone2d_node->get_length() * MIN(current_bone2d_node->get_global_scale().x, current_bone2d_node->get_global_scale().y); float length = current_bone2d_node_length / (previous_pose.get_origin() - current_pose.get_origin()).length(); Vector2 finish_position = previous_pose.get_origin().lerp(current_pose.get_origin(), length); |