private TrigSolution createTrigSolution() { TrigSolution t_trigSolution = new TrigSolution(); float t_lengthMiddlePoint = m_upperLength / (m_upperLength + m_lowerLength); float t_lengthOfAdjacent = FindLinearEndpoint().magnitude *t_lengthMiddlePoint; Vector3 t_verticalMarkerLocation = FindLinearEndpoint() * t_lengthOfAdjacent; t_trigSolution.m_verticalMarkerLocation = t_verticalMarkerLocation; float t_opposite = Mathf.Sqrt(Mathf.Pow(m_upperLength, 2) - Mathf.Pow(t_lengthOfAdjacent, 2)); t_trigSolution.m_markerHeight = t_opposite; Vector3 t_rotationUpVector = Quaternion.LookRotation(FindLinearEndpoint(), -Vector3.up) * Vector3.up; Quaternion t_verticalMarkerRotation = Quaternion.LookRotation(t_rotationUpVector); t_trigSolution.m_verticalMarkerRotation = t_verticalMarkerRotation; //Important! Vector3 t_segmentJointPosition = t_verticalMarkerLocation + (t_rotationUpVector * t_opposite); t_trigSolution.m_segmentJointPosition = t_segmentJointPosition; return(t_trigSolution); }
// Update is called once per frame void Update() { FirstLookAtSecondPoint(); FirstArmScale(); TrigSolution t_trigSolution = createTrigSolution(); m_verticalMarkerParent.transform.localPosition = m_IKOrigin.transform.position + t_trigSolution.m_verticalMarkerLocation; m_verticalMarkerParent.transform.localRotation = t_trigSolution.m_verticalMarkerRotation; m_joint.transform.localPosition = m_IKOrigin.transform.position + t_trigSolution.m_segmentJointPosition; ArrowLength = t_trigSolution.m_markerHeight; m_verticalMarkerParent.transform.localScale = new Vector3(1, 1, ArrowLength); }