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 ?

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();
}
1 Like

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;
}