Last active
April 15, 2023 19:21
-
-
Save kristiandelay/c1f17a39c5db7689b8291942b4ff1afa to your computer and use it in GitHub Desktop.
Trying to figure out how to set the effector transform of LimbSolver2D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Transform FindDeepChild(Transform parent, string name) | |
| { | |
| foreach (Transform child in parent) | |
| { | |
| if (child.name == name) | |
| { | |
| return child; | |
| } | |
| else | |
| { | |
| Transform result = FindDeepChild(child, name); | |
| if (result != null) | |
| { | |
| return result; | |
| } | |
| } | |
| } | |
| return null; | |
| } | |
| public virtual bool FindFeetAndArms() | |
| { | |
| bool continue_setup = true; | |
| if (leftHand == null) | |
| { | |
| leftHand = FindDeepChild(character.transform, "LeftHand"); | |
| } | |
| if (rightHand == null) | |
| { | |
| rightHand = FindDeepChild(character.transform, "RightHand"); | |
| } | |
| if (leftFoot == null) | |
| { | |
| leftFoot = FindDeepChild(character.transform, "LeftFoot"); | |
| } | |
| if (rightFoot == null) | |
| { | |
| rightFoot = FindDeepChild(character.transform, "RightFoot"); | |
| } | |
| return continue_setup; | |
| } | |
| public virtual LimbSolver2D CreateLimbSolver(string ikSolverName) | |
| { | |
| Transform iKTarget = character.transform.Find(ikSolverName); | |
| LimbSolver2D limbSolver = null; | |
| if (iKTarget == null) | |
| { | |
| GameObject IKGO = new GameObject | |
| { | |
| name = ikSolverName | |
| }; | |
| limbSolver = IKGO.AddComponent<LimbSolver2D>(); | |
| limbSolver.name = ikSolverName; | |
| limbSolver.transform.parent = character.transform; | |
| limbSolver.transform.localPosition = Vector3.zero; | |
| // I want to set the effector transform to the respective target. | |
| // This seems to be done easily in the editor just drag your bone to the effector target.. | |
| // I am not seeing any code to do this am i overlooking this functionality? | |
| // pseudo example: | |
| //limbSolver.effector = iKTarget; | |
| } | |
| else | |
| { | |
| limbSolver = iKTarget.GetComponent<LimbSolver2D>(); | |
| } | |
| return limbSolver; | |
| } | |
| public virtual bool SetupIKRig() | |
| { | |
| LimbSolver2D[] limbIKs = new LimbSolver2D[4]; | |
| limbIKs[0] = CreateLimbSolver("LeftArmIK"); ; | |
| limbIKs[1] = CreateLimbSolver("RightArmIK"); ; | |
| limbIKs[2] = CreateLimbSolver("LeftLegIK"); ; | |
| limbIKs[3] = CreateLimbSolver("RightLegIK"); ; | |
| IKManager2D ikManager2D = character.GetComponent<IKManager2D>(); | |
| if (ikManager2D == null) | |
| { | |
| ikManager2D = character.AddComponent<IKManager2D>(); | |
| } | |
| ikManager2D.solvers.Clear(); | |
| foreach (var limbIK in limbIKs) | |
| { | |
| ikManager2D.solvers.Add(limbIK); | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment