Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question How can I add many Weighted Transforms within a single script?

Discussion in 'Animation Rigging' started by gioperezcolon, Jun 12, 2022.

  1. gioperezcolon

    gioperezcolon

    Joined:
    Jan 24, 2022
    Posts:
    2
    Hi, I've been working on a shooter game and made the "pose" of player hands attached to multiple constraints that copy transforms within the Weapon scriptable object that the player is holding. In theory this lets me edit how the hands properly grip whatever weapon the player is holding, however, the problem is that only the first line to use New Weighted Transform links the constraint to the transform while all the others aren't linked. Do you guys know how to fix this?
    Code (CSharp):
    1.  void Update()
    2.     {
    3.         hasWeapon = cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetComponent<GunScript>().hasWeapon;
    4.         if (hasWeapon && !isTargetSet)
    5.         {
    6.             //Left Hand
    7.             leftHandIK.data.target = cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip");
    8.  
    9.  
    10.             WTleftThumb = new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LThumb"), 1);
    11.             leftThumb.data.sourceObjects.Add(WTleftThumb);
    12.             WTleftThumbMid = new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LThumb/Mid"), 1);
    13.             leftThumbMid.data.sourceObjects.Add(WTleftThumbMid);
    14.  
    15.             WTleftThumbTip = new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LThumb/Tip"), 1);
    16.             leftThumbTip.data.sourceObjects.Add(WTleftThumbTip);
    17.             Debug.Log("Checkpoint");
    18.  
    19.  
    20.             leftIndex.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LIndex"), 1));
    21.             leftIndexMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LIndex/LIMid"), 1));
    22.             leftIndexTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LIndex/LITip"), 1));
    23.  
    24.             leftMiddle.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LMiddle"), 1));
    25.             leftMiddleMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LMiddle/Mid"), 1));
    26.             leftMiddleTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LMiddle/Tip"), 1));
    27.  
    28.             leftRing.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LRing"), 1));
    29.             leftRingMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LRing/Mid"), 1));
    30.             leftRingTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LRing/Tip"), 1));
    31.  
    32.             leftPinky.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LPinky"), 1));
    33.             leftPinkyMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LPinky/Mid"), 1));
    34.             leftPinkyTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/LeftHandGrip/LPinky/Tip"), 1));
    35.  
    36.             //Right Hand
    37.             rightHandIK.data.target = cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip");
    38.  
    39.             rightThumb.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RThumb"), 1));
    40.             rightThumbMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RThumb/Mid"), 1));
    41.             rightThumbTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RThumb/Tip"), 1));
    42.  
    43.             rightIndex.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RIndex"), 1));
    44.             rightIndexMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RIndex/Mid"), 1));
    45.             rightIndexTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RIndex/Tip"), 1));
    46.  
    47.             rightMiddle.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RMiddle"), 1));
    48.             rightMiddleMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RMiddle/Mid"), 1));
    49.             rightMiddleTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RMiddle/Tip"), 1));
    50.  
    51.             rightRing.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RRing"), 1));
    52.             rightRingMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RRing/Mid"), 1));
    53.             rightRingTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RRing/Tip"), 1));
    54.  
    55.             rightPinky.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RPinky"), 1));
    56.             rightPinkyMid.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RPinky/Mid"), 1));
    57.             rightPinkyTip.data.sourceObjects.Add(new WeightedTransform(cameraHolder.transform.Find("Recoil/MainCamera/Weapon").GetChild(0).transform.Find("Anchors/Design/GripReference/RightHandGrip/RPinky/Tip"), 1));
    58.            
    59.             isTargetSet = true;
    60.             rigBuilder.Build();
    61.         }
    62.  
    63.     }
     
  2. gioperezcolon

    gioperezcolon

    Joined:
    Jan 24, 2022
    Posts:
    2
    nvm figured it out