- Home /
Is there a way to set the source object target via script for Two Bone IK constraint ?
I am using two bone IK constraint for my character to hold on to his weapons by constraining the hands to transform that correspond to the weapon handle ( lets call these handle transforms). Naturally, each weapon will come with its own handle transforms. I was thinking I could change the source object target dynamically during run-time to the equipped weapon's handle transforms, is this supported by unity ?
I'm having this issue as well. I'm able to set the source in the data.target but my player is still not connecting up with the target IK. I'm wondering if there is some update command that should be called to tell the animator that a new target is present.
Answer by Cyril5 · Jul 20, 2021 at 09:51 PM
Hello,
you have to rebuild your rig builder to apply your new settings. Example :
public TwoBoneIKConstraint leftHandIk;
public TwoBoneIKConstraint rightHandIK;
public RigBuilder rigBuilder;
public Transform rightHandTarget;
public Transform leftHandTarget;
void Start()
{
leftHandIk.data.target = rightHandTarget;
rightHandIK.data.target = leftHandTarget;
rigBuilder.Build();
}
Answer by notaspyaraceku · Feb 27, 2021 at 05:34 PM
I had the same problem but I managed to solve it!! It's the "data" variable!
TwoBoneIKConstraint ik;
void Start()
{
ik.data.target.position = Vector3.zero;
}