IK demo: Fixed bug in FABRIK IK that would cause the right arm to freak out by changing the middle joint code.

This commit is contained in:
TwistedTwigleg
2020-01-29 17:52:25 -05:00
parent 40bcc0f55f
commit 2e681e132a
3 changed files with 6 additions and 3 deletions

View File

@@ -190,8 +190,9 @@ func solve_chain():
# If we are using middle joint target (and have more than 2 bones), move our middle joint towards it!
if use_middle_joint_target == true:
if bone_nodes.size() > 2:
var middle_point_pos = middle_joint_target.global_transform
bone_nodes[bone_nodes.size()/2].global_transform.origin = middle_point_pos.origin
var middle_point_pos = middle_joint_target.global_transform.origin
var middle_point_pos_diff = (middle_point_pos - bone_nodes[bone_nodes.size()/2].global_transform.origin)
bone_nodes[bone_nodes.size()/2].global_transform.origin += middle_point_pos_diff.normalized()
# Get the difference between our end effector (the final bone in the chain) and the target
var dif = (bone_nodes[bone_nodes.size()-1].global_transform.origin - target_pos).length()

View File

@@ -95,7 +95,6 @@ __meta__ = {
skeleton_path = NodePath("../../../BattleBot/Armature/Skeleton")
bones_in_chain = PoolStringArray( "Left_UpperArm", "Left_LowerArm" )
bones_in_chain_lengths = PoolRealArray( 1.97, 3 )
chain_iterations = 10
limit_chain_iterations = false
use_middle_joint_target = true

View File

@@ -133,6 +133,9 @@ margin_right = -5.0
margin_bottom = -10.0
text = "Next scene"
script = ExtResource( 8 )
__meta__ = {
"_edit_use_anchors_": false
}
scene_to_change_to = "res://fabrik_ik.tscn"
[editable path="BattleBot"]