Ejemplo n.º 1
0
        /// <summary>
        /// break from trigger matching target
        /// </summary>
        public void breakTrigger()
        {
#if DEBUG_INFO
            if (!m_initialized)
            {
                Debug.LogError("Component not initialized! " + " < " + this.ToString() + ">");
                return;
            }
#endif

            if (!enabled)
            {
                return;
            }
            m_Character.animator.InterruptMatchTarget();
            if (m_CurrentActiveTrigger)
            {
                m_CurrentActiveTrigger.end(m_Character, m_IKHelper);
            }

            m_Character.animator.SetBool(/*"pOnLedge"*/ HashIDs.OnLedgeBool, false);
            m_Character.animator.SetBool(/*"pGrabLedgeUp"*/ HashIDs.GrabLedgeUpBool, false);
            m_Character.animator.SetBool(/*"pGrabLedgeDown"*/ HashIDs.GrabLedgeDownBool, false);
            m_Character.animator.SetBool(/*"pGrabLedgeLeft"*/ HashIDs.GrabLedgeLeftBool, false);
            m_Character.animator.SetBool(/*"pGrabLedgeRight"*/ HashIDs.GrabLedgeRightBool, false);
            m_Character.animator.SetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool, false);

            m_Character.jumpAllowed = true;
            m_Character.enablePhysics();
            m_Character.rigidBody.isKinematic = false;
            m_Character.setMoveMode(TPCharacter.MovingMode.RotateToDirection);
            m_Character.disableCapsuleScale = false;
            m_Character.restoreCapsuleSize();
            m_Character.disableMove        = false;
            m_Character.disableGroundCheck = false;
            m_Character.ledgeMove          = false;
            m_Character.animatorDampTime   = 0.1f;
            m_Character.setLedge(null);
            m_IKHelper.handIKMode = IKMode.Default;
            m_IKHelper.feetIKMode = IKMode.Default;

            m_TriggerAllowed = false;
            m_TriggerTime    = 0.0f;

            disableIK();
            m_TriggerActive = false;

            if (OnTriggerEnd != null)
            {
                OnTriggerEnd();
            }

            m_CurrentActiveTrigger = null;
        }
Ejemplo n.º 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);
            }

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