/// <summary>
        /// start trigger interaction
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbsIK">ik helper</param>
        /// <param name="use">use flag</param>
        /// <param name="jump">jump flag</param>
        /// <param name="v">vertical value</param>
        /// <param name="h">horizontal value</param>
        /// <returns>all succeded</returns>
        public override bool start(TPCharacter character, IKHelper limbsIK, bool use, bool secondaryUse, bool jump, float v, float h)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }
            if (!Target)
            {
#if DEBUG_INFO
                Debug.LogWarning("trigger target not assigned!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }

            if (!use)
            {
                return(false);
            }

            Vector3 pt1, pt2;
            float   scalez = Target.localScale.z * 0.5f;
            Utils.CalculateLinePoints(Target, out pt1, out pt2, -scalez, switchTargetDirection);
            Vector3 checkpos = character.transform.position;
            Vector3 closest  = MathUtils.GetClosestPoint2Line(pt1, pt2, ref checkpos);
            m_TriggerInfo.avatarTarget = catchTarget;

            m_TriggerInfo.transform      = Target;
            m_TriggerInfo.pos_offset     = closest - Target.position;
            m_TriggerInfo.stateName      = "Base Layer.TRIGGERS.JumpForward";
            character.disableMove        = true;
            character.rigidBody.velocity = Vector3.zero;
            m_TriggerInfo.doMatchTarget  = true;
            character.OnLerpEnd          = () =>
            {
                character.animator.SetBool(/*"pJumpForward"*/ HashIDs.JumpForwardBool, true);
                m_TriggerInfo.targetRotation = character.transform.rotation;
                m_TriggerInfo.startRotation  = character.transform.rotation;
                character.triggerRootMotion  = true;

                character.OnLerpEnd = null;
            };

            Quaternion rotation = transform.rotation;
            Vector3    euler    = rotation.eulerAngles;
            euler.z = 0.0f;
            euler.x = 0.0f;
            Quaternion fromEuler = Quaternion.Euler(euler);
            if (switchTargetDirection)
            {
                fromEuler *= Quaternion.AngleAxis(180, character.transform.up);
            }

            float forwAmt = Mathf.Min(character.forwardAmount, 0.5f);
            character.lerpToTransform(null, fromEuler,
                                      0f, 0.2f, forwAmt, false, false);
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// start trigger interaction
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbsIK">ik helper</param>
        /// <param name="use">use flag</param>
        /// <param name="jump">jump flag</param>
        /// <param name="v">vertical value</param>
        /// <param name="h">horizontal value</param>
        /// <returns>all succeded</returns>
        public override bool start(TPCharacter character, IKHelper limbsIK, bool use, bool secondaryUse, bool jump, float v, float h)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }
            if (!Target)
            {
#if DEBUG_INFO
                Debug.LogWarning("trigger target not assigned!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }

            if (!use)
            {
                return(false);
            }

            // example of IK
            if (limbsIK && enableCatchIK)
            {
                limbsIK.RHandIKEnabled = true;
                limbsIK.RHWeightTime   = 0.0f;
                limbsIK.setIKDirection(true);
                limbsIK.handIKMode = IKMode.Default;
                Transform rightHandT = character.animator.GetBoneTransform(HumanBodyBones.RightHand);
                Vector3?  closest2RH = closestPoint(rightHandT.position);
                limbsIK.RHPosition = closest2RH.Value;
            }

            if (turnToLedge)
            {
                Vector3?closestMid = closestPoint(character.transform.position);
                Vector3 direction  = (closestMid.Value - character.transform.position);
                direction.y = 0.0f;
                direction.Normalize();


                Vector3 pt1, pt2;
                float   scalez = Target.localScale.z * 0.5f;
                bool    face   = Vector3.Dot(Target.forward, direction) < 0;
                Utils.CalculateLinePoints(Target, out pt1, out pt2, -scalez, face);
                Vector3 checkpos = character.transform.position;
                Vector3 closest  = MathUtils.GetClosestPoint2Line(pt1, pt2, ref checkpos);

                m_TriggerInfo.avatarTarget = AvatarTarget.RightFoot;

                m_TriggerInfo.transform      = Target;
                m_TriggerInfo.pos_offset     = closest - Target.position;
                m_TriggerInfo.stateName      = "Base Layer.TRIGGERS.JumpOn";
                character.disableMove        = true;
                character.rigidBody.velocity = Vector3.zero;
                m_TriggerInfo.doMatchTarget  = true;
                character.OnLerpEnd          = () =>
                {
                    character.animator.SetBool(HashIDs.JumpOnBool, true);
                    Quaternion targetRot = Quaternion.LookRotation(direction);
                    m_TriggerInfo.targetRotation = targetRot;
                    m_TriggerInfo.startRotation  = character.transform.rotation;
                    character.triggerRootMotion  = true;

                    character.OnLerpEnd = null;
                };
                Quaternion rotation = Quaternion.LookRotation(direction);

                float forwAmt = Mathf.Min(character.forwardAmount, 0.5f);
                character.lerpToTransform(null, rotation,
                                          0f, 0.2f, forwAmt, false, false);
            }
            else
            {
                Vector3 pt1, pt2;
                float   scalez = Target.localScale.z * 0.5f;
                Utils.CalculateLinePoints(Target, out pt1, out pt2, -scalez, switchTargetDirection);
                Vector3 checkpos = character.transform.position;
                Vector3 closest  = MathUtils.GetClosestPoint2Line(pt1, pt2, ref checkpos);


                m_TriggerInfo.avatarTarget = AvatarTarget.RightFoot; //RightHand;

                m_TriggerInfo.transform      = Target;
                m_TriggerInfo.pos_offset     = closest - Target.position;
                m_TriggerInfo.stateName      = "Base Layer.TRIGGERS.JumpOn";
                character.disableMove        = true;
                character.rigidBody.velocity = Vector3.zero;
                m_TriggerInfo.doMatchTarget  = true;

                character.OnLerpEnd = () =>
                {
                    character.animator.SetBool(HashIDs.JumpOnBool, true);
                    Quaternion targetRot   = Target.rotation;
                    Vector3    targetEuler = targetRot.eulerAngles;
                    targetEuler.z = 0.0f;
                    targetEuler.x = 0.0f;
                    if (switchTargetDirection)
                    {
                        targetEuler.y += 180.0f;
                    }
                    Quaternion fromTargetEuler = Quaternion.Euler(targetEuler);
                    m_TriggerInfo.targetRotation = fromTargetEuler;
                    m_TriggerInfo.startRotation  = character.transform.rotation;
                    character.triggerRootMotion  = true;

                    character.OnLerpEnd = null;
                };
                Quaternion rotation = transform.rotation;
                Vector3    euler    = rotation.eulerAngles;
                euler.z = 0.0f;
                euler.x = 0.0f;
                Quaternion fromEuler = Quaternion.Euler(euler);
                float      forwAmt   = Mathf.Min(character.forwardAmount, 0.5f);
                character.lerpToTransform(null, fromEuler,
                                          0f, 0.2f, forwAmt, false, false);
            }
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// start trigger interaction
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbsIK">ik helper</param>
        /// <param name="use">use flag</param>
        /// <param name="jump">jump flag</param>
        /// <param name="v">vertical value</param>
        /// <param name="h">horizontal value</param>
        /// <returns>all succeded</returns>
        public override bool start(TPCharacter character, IKHelper limbsIK, bool use, bool secondaryUse, bool jump, float v, float h)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }
            if (!Target)
            {
#if DEBUG_INFO
                Debug.LogWarning("trigger target not assigned!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }



            if (!use)
            {
                return(false);
            }

            float scalez = Target.localScale.z * 0.5f;
            character.setLedge(Target, false, -scalez);



            Vector3 checkpos = character.transform.position;
            Vector3 closest  = MathUtils.GetClosestPoint2Line(character.ledge.leftPoint,
                                                              character.ledge.rightPoint, ref checkpos);

            bool moveright = true;
            m_TriggerInfo.avatarTarget = AvatarTarget.RightHand;
            if (closest == character.ledge.leftPoint)
            {
                m_TriggerInfo.avatarTarget = AvatarTarget.LeftHand;
                moveright = false;
            }
            m_TriggerInfo.transform     = Target;
            m_TriggerInfo.pos_offset    = closest - Target.position;
            m_TriggerInfo.CatchPosition = closest;

            character.disableLedgeConstraint = true; // disable ledge constraining or character may be stuck if outside ledge bounds
            character.disableMove            = true;
            character.rigidBody.velocity     = Vector3.zero;

            if (limbsIK)
            {
                limbsIK.LHandIKEnabled = false;
                limbsIK.RHandIKEnabled = false;
                limbsIK.LFootIKEnabled = false;
                limbsIK.RFootIKEnabled = false;

                limbsIK.checkHang = false;

                limbsIK.handIKMode   = IKMode.ToLine;
                limbsIK.LeftHandPtA  = character.ledge.leftPoint;
                limbsIK.LeftHandPtB  = character.ledge.rightPoint;
                limbsIK.RightHandPtA = character.ledge.leftPoint;
                limbsIK.RightHandPtB = character.ledge.rightPoint;


                Vector3 pos = character.transform.position;
                closest = MathUtils.GetClosestPoint2Line(character.ledge.leftPoint, character.ledge.rightPoint, ref pos);
                bool checkUnder = _checkIsWallUnderTarget(character, limbsIK, closest, Target, moveright);
                if (checkUnder)
                {
                    character.animator.SetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool, false);
                    m_TriggerInfo.stateName         = "Base Layer.LEDGE.JumpToLedgeState";
                    limbsIK.currentRelLedgePosition =
                        limbsIK.ledgeRelativePosition;
                }
                else
                {
                    character.animator.SetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool, true);
                    m_TriggerInfo.stateName         = "Base Layer.LEDGE.Jump2Ledge_Hang";
                    limbsIK.currentRelLedgePosition =
                        limbsIK.ledgeRelativePositionHang;
                }
            }
            else
            {
                character.animator.SetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool, true);
                m_TriggerInfo.stateName = "Base Layer.LEDGE.Jump2Ledge_Hang";
            }

            m_TriggerInfo.doMatchTarget = true;

            character.OnLerpEnd = () =>
            {
                character.disableMove = true;
                character.disablePhysics(true, true);
                character.animator.SetBool(/*"pGrabLedgeUp"*/ HashIDs.GrabLedgeUpBool, true);
                character.jumpAllowed = false;

                Quaternion targetRot   = Target.rotation;
                Vector3    targetEuler = targetRot.eulerAngles;
                targetEuler.z = 0.0f;
                targetEuler.x = 0.0f;
                if (switchTargetDirection)
                {
                    targetRot *= Quaternion.AngleAxis(180, character.transform.up);
                }
                Quaternion fromTargetEuler = Quaternion.Euler(targetEuler);

                m_TriggerInfo.targetRotation = fromTargetEuler;
                m_TriggerInfo.startRotation  = character.transform.rotation;

                character.triggerRootMotion = true;

                character.OnLerpEnd = null;
            };
            Quaternion rotation = transform.rotation;
            Vector3    euler    = rotation.eulerAngles;
            euler.z = 0.0f;
            euler.x = 0.0f;
            Quaternion fromEuler = Quaternion.Euler(euler);
            character.lerpToTransform(null, fromEuler,
                                      0f, 0.2f);
            return(true);
        }
        /// <summary>
        /// start trigger interaction
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbsIK">ik helper</param>
        /// <param name="use">use flag</param>
        /// <param name="jump">jump flag</param>
        /// <param name="v">vertical value</param>
        /// <param name="h">horizontal value</param>
        /// <returns>all succeded</returns>
        public override bool start(TPCharacter character, IKHelper limbsIK, bool use, bool secondaryUse, bool jump, float v, float h)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }
            if (!Target)
            {
#if DEBUG_INFO
                Debug.LogWarning("trigger target not assigned!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }

            if (!use)
            {
                return(false);
            }

            //if (!m_TriggerInfo) m_TriggerInfo = new TriggerInfo();

            m_TriggerInfo.doMatchTarget      = false;
            m_TriggerInfo.doRotationToTarget = false;

            Vector3 direction = GoingUp ? Target.forward : -Target.forward;

            float distanceFromTarget = (character.transform.position - Target.position).magnitude;
            float angle        = Vector3.Angle(character.transform.forward, direction) * 0.002f;
            float pos_rot_time = distanceFromTarget + angle;

            if (pos_rot_time < 0.1f)
            {
                if (limbsIK)
                {
                    limbsIK.handIKMode = IKMode.ToLine;
                    limbsIK.setIKDirection(true);

                    if (LeftHandHold)
                    {
                        limbsIK.LeftHandPtA    = LeftHandHold.position - LeftHandHold.up * 100.0f;
                        limbsIK.LeftHandPtB    = LeftHandHold.position + LeftHandHold.up * 100.0f;
                        limbsIK.LHandIKEnabled = true;
                        limbsIK.LHWeightTime   = 0.0f;
                    }
                    else
                    {
                        limbsIK.LHandIKEnabled = false;
                    }


                    if (RightHandHold)
                    {
                        limbsIK.RightHandPtA   = RightHandHold.position - RightHandHold.up * 100.0f;
                        limbsIK.RightHandPtB   = RightHandHold.position + RightHandHold.up * 100.0f;
                        limbsIK.RHandIKEnabled = true;
                        limbsIK.RHWeightTime   = 0.0f;
                    }
                    else
                    {
                        limbsIK.RHandIKEnabled = false;
                    }



                    limbsIK.feetIKMode = IKMode.ToPlane;
                    if (LeftFootHold)
                    {
                        Vector3 lpt1 = LeftFootHold.position;
                        Vector3 lpt2 = lpt1 + LeftFootHold.up;
                        Vector3 lpt3 = lpt1 + LeftFootHold.forward;
                        limbsIK.LeftFootPlane.Set3Points(lpt1, lpt2, lpt3);
                        limbsIK.LFootIKEnabled = true;
                    }
                    else
                    {
                        limbsIK.LFootIKEnabled = false;
                    }

                    if (RightFootHold)
                    {
                        Vector3 rpt1 = RightFootHold.position;
                        Vector3 rpt2 = rpt1 + RightFootHold.up;
                        Vector3 rpt3 = rpt1 + RightFootHold.forward;
                        limbsIK.RightFootPlane.Set3Points(rpt1, rpt2, rpt3);
                        limbsIK.RFootIKEnabled = true;
                    }
                    else
                    {
                        limbsIK.RFootIKEnabled = false;
                    }
                }



                character.disablePhysics(false, true);
                character.OnSetTransform = () =>
                {
                    //set steps audio clips to character
                    character.audioManager.ladderClips = ladderSounds;

                    character.disablePhysics(false, true);
                    if (GoingUp)
                    {
                        character.animator.SetBool(/*"pLadderUp"*/ HashIDs.LadderUpBool, true);
                    }
                    else
                    {
                        character.animator.SetBool(/*"pLadderDown"*/ HashIDs.LadderDownBool, true);
                    }
                    character.animator.SetInteger(/*"pLadderSize"*/ HashIDs.LadderSizeInt, (int)LadderSize);
                    character.OnSetTransform = null;
                };

                Quaternion targetRot = Target.rotation;
                if (switchTargetDirection)
                {
                    targetRot *= Quaternion.AngleAxis(180, character.transform.up);
                }
                if (!GoingUp)
                {
                    targetRot *= Quaternion.AngleAxis(180, character.transform.up);
                }
                character.setTransform(Target.position, targetRot, true);


                character.triggerRootMotion = true;
            }
            else
            {
                float forw   = 0.5f;
                bool  crouch = false;
                character.OnLerpEnd = () =>
                {
                    if (limbsIK)
                    {
                        limbsIK.handIKMode = IKMode.ToLine;
                        limbsIK.setIKDirection(true);
                        if (LeftHandHold)
                        {
                            limbsIK.LeftHandPtA    = LeftHandHold.position - LeftHandHold.up * 100.0f;
                            limbsIK.LeftHandPtB    = LeftHandHold.position + LeftHandHold.up * 100.0f;
                            limbsIK.LHandIKEnabled = true;
                            limbsIK.LHWeightTime   = 0.0f;
                        }
                        else
                        {
                            limbsIK.LHandIKEnabled = false;
                        }
                        if (RightHandHold)
                        {
                            limbsIK.RightHandPtA   = RightHandHold.position - RightHandHold.up * 100.0f;
                            limbsIK.RightHandPtB   = RightHandHold.position + RightHandHold.up * 100.0f;
                            limbsIK.RHandIKEnabled = true;
                            limbsIK.RHWeightTime   = 0.0f;
                        }
                        else
                        {
                            limbsIK.RHandIKEnabled = false;
                        }
                        limbsIK.feetIKMode = IKMode.ToPlane;
                        if (LeftFootHold)
                        {
                            Vector3 lpt1 = LeftFootHold.position;
                            Vector3 lpt2 = lpt1 + LeftFootHold.up;
                            Vector3 lpt3 = lpt1 + LeftFootHold.forward;
                            limbsIK.LeftFootPlane.Set3Points(lpt1, lpt2, lpt3);
                            limbsIK.LFootIKEnabled = true;
                        }
                        else
                        {
                            limbsIK.LFootIKEnabled = false;
                        }
                        if (RightFootHold)
                        {
                            Vector3 rpt1 = RightFootHold.position;
                            Vector3 rpt2 = rpt1 + RightFootHold.up;
                            Vector3 rpt3 = rpt1 + RightFootHold.forward;
                            limbsIK.RightFootPlane.Set3Points(rpt1, rpt2, rpt3);
                            limbsIK.RFootIKEnabled = true;
                        }
                        else
                        {
                            limbsIK.RFootIKEnabled = false;
                        }
                    }

                    //set steps audio clips to character
                    character.audioManager.ladderClips = ladderSounds;


                    character.disablePhysics(false, true);
                    if (GoingUp)
                    {
                        character.animator.SetBool(/*"pLadderUp"*/ HashIDs.LadderUpBool, true);
                    }
                    else
                    {
                        character.animator.SetBool(/*"pLadderDown"*/ HashIDs.LadderDownBool, true);
                    }
                    character.animator.SetInteger(/*"pLadderSize"*/ HashIDs.LadderSizeInt, (int)LadderSize);
                    character.transform.position = Target.position;
                    character.triggerRootMotion  = true;
                    character.OnLerpEnd          = null;
                };
                character.disableMove = true;
                Quaternion targetRot = Target.rotation;
                if (switchTargetDirection)
                {
                    targetRot *= Quaternion.AngleAxis(180, character.transform.up);
                }
                if (!GoingUp)
                {
                    targetRot *= Quaternion.AngleAxis(180, character.transform.up);
                }
                character.lerpToTransform(
                    Target.position,
                    targetRot,
                    pos_rot_time,
                    pos_rot_time,
                    forw,
                    crouch
                    );
            }
            return(true);
        }