Пример #1
0
        /// <summary>
        /// end trigger animations
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbsIK">ik helper</param>
        public override void end(TPCharacter character, IKHelper limbsIK)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return;
            }
            if (!Target)
            {
#if DEBUG_INFO
                Debug.LogWarning("trigger target not assigned!" + " < " + this.ToString() + ">");
#endif
                return;
            }


            character.triggerRootMotion = false;
            character.disableMove       = false;
            character.setMoveMode(TPCharacter.MovingMode.Ledge);

            OrbitCameraController oc = character.GetComponentInChildren <OrbitCameraController>();
            if (oc)
            {
                oc.additiveRotation = true;
            }

            character.disableCapsuleScale = true;
            character.animator.SetBool(/*"pGrabLedgeUp"*/ HashIDs.GrabLedgeUpBool, false);
            character.animator.SetBool(/*"pOnLedge"*/ HashIDs.OnLedgeBool, true);
            character.animatorDampTime       = 0.0f;
            character.ledgeMove              = true;
            character.disableLedgeConstraint = false;
            character.fullStop();
            character.jumpAllowed = true;

            if (limbsIK)
            {
                limbsIK.RHandIKEnabled = true;
                limbsIK.LFootIKEnabled = true;
                limbsIK.RFootIKEnabled = true;
                limbsIK.LHandIKEnabled = true;
                limbsIK.LFWeightTime   = 0.0f;
                limbsIK.RFWeightTime   = 0.0f;

                limbsIK.startLedgeAdjust(m_TriggerInfo.targetRotation);
                limbsIK.checkHang = true;
            }
            if (character.animator.GetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool))
            {
                character.restoreCapsuleSize();
            }
            else
            {
                character.scaleCapsuleToHalf();
            }
        }
Пример #2
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;
        }
        /// <summary>
        /// method for checking does player is facing wall when on ledge
        /// </summary>
        private void _checkHangFunc()
        {
            if (!m_Character.ledgeMove)
            {
                return;
            }
            if (!m_CheckHang)
            {
                return;
            }


            bool       hang    = true;
            bool       hanging = m_Character.animator.GetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool);
            float      radius  = m_Character.capsule.radius * 0.38f;
            RaycastHit hit;
            int        mask       = m_Character.layers;
            Vector3    checkStart = transform.position;

            Vector3 closest = MathUtils.GetClosestPoint2Line(m_Character.ledge.leftPoint,
                                                             m_Character.ledge.rightPoint, ref checkStart);

            Ray   ray     = new Ray(checkStart, Vector3.up);
            float rayDist = 0.0f;

            if (m_Character.ledge.plane.Raycast(ray, out rayDist))
            {
                closest = checkStart + Vector3.up * rayDist;
                closest = MathUtils.GetClosestPoint2Line(m_Character.ledge.leftPoint,
                                                         m_Character.ledge.rightPoint, ref closest);
            }


            Vector3 offset = new Vector3(0.0f, 1.0f, 0.25f);

            offset = transform.rotation * offset;
            Vector3 pos  = closest - offset;
            float   dist = hangCheckDistance + 0.25f;

            ray = new Ray(pos, transform.forward);

#if DEBUG_INFO
            HANGCHECKCOL  = Color.white;
            HANGCHECKDIST = dist;
            HANGCHECKPOS  = ray.origin;
#endif


            float MAX_DIST_NOMOVE = 0.32f;
            m_LedgeAdjustion = Vector3.zero;

            if (Physics.SphereCast(ray, radius, out hit, dist, mask))
            {
#if DEBUG_INFO
                HANGCHECKCOL = Color.red;
#endif
                if (hit.distance > MAX_DIST_NOMOVE)
                {
                    float addedDist = MAX_DIST_NOMOVE - hit.distance;
                    m_LedgeAdjustion = -transform.forward * addedDist;
                }

                hang = false;
            }

            if (hang)
            {
                if (!hanging)
                {
                    m_Character.animator.SetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool, true);
                    currentRelLedgePosition = ledgeRelativePositionHang;
                    startLedgeAdjust(transform.rotation);
                    m_Character.restoreCapsuleSize();
                }
            }
            else
            {
                if (hanging)
                {
                    m_Character.animator.SetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool, false);
                    currentRelLedgePosition = ledgeRelativePosition;
                    startLedgeAdjust(transform.rotation);
                    m_Character.scaleCapsuleToHalf();
                }
            }
        }