/// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// executes on match target start
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbsIK">ik helper</param>
        public override void onMatchTargetStart(TPCharacter character, IKHelper limbsIK)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return;
            }


            if (limbsIK)
            {
                limbsIK.LHandIKEnabled = true;
                limbsIK.LHWeightTime   = 0.0f;
                limbsIK.RHandIKEnabled = true;
                limbsIK.RHWeightTime   = 0.0f;
                limbsIK.LFootIKEnabled = false;
                limbsIK.RFootIKEnabled = false;
                limbsIK.setIKDirection(true);
            }
            m_TriggerInfo.doRotationToTarget = true;
            m_TriggerInfo.rot_time           = 0.0f;


            base.onMatchTargetStart(character, limbsIK);
        }
        /// <summary>
        /// initialize class
        /// </summary>
        /// <returns>true if succeded initialization</returns>
        public bool initialize()
        {
            if (m_initialized)
            {
                return(true);
            }
            m_Character = GetComponent <TPCharacter>();
            if (!m_Character)
            {
                Debug.LogError("cannot find component 'TPCharacter'" + " < " + this.ToString() + ">"); return(false);
            }
            m_Character.initialize();
            m_Animator = m_Character.animator;
            if (!m_Animator)
            {
                Debug.LogError("cannot find 'Animator' component" + " < " + this.ToString() + ">"); return(false);
            }

            m_LFoot = m_Animator.GetBoneTransform(HumanBodyBones.LeftFoot);
            if (!m_LFoot)
            {
                Debug.LogError("Cannot find left foot transform."); return(false);
            }
            m_RFoot = m_Animator.GetBoneTransform(HumanBodyBones.RightFoot);
            if (!m_RFoot)
            {
                Debug.LogError("Cannot find right foot transform."); return(false);
            }


            m_initialized = true;
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// check if there is wall in front of character
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbIK">ik helper class</param>
        /// <param name="inpos">input position</param>
        /// <param name="target">target transform</param>
        /// <param name="moveright">move right or left</param>
        /// <returns>returns true if wall is in front otherwise false</returns>
        private bool _checkIsWallUnderTarget(TPCharacter character, IKHelper limbIK, Vector3 inpos, Transform target, bool moveright = true)
        {
            Vector3 offset = new Vector3(0.0f, character.capsule.height * 0.5f, 0.25f);

            offset = target.rotation * offset;
            Vector3 pos         = inpos - offset;
            float   ledgeLength = (character.ledge.rightPoint - character.ledge.leftPoint).magnitude;
            Vector3 ledgeDir    = character.getLedgeDirection();
            float   dirOffset   = Mathf.Min(ledgeLength, character.capsule.radius);

            if (moveright)
            {
                pos -= ledgeDir * dirOffset;
            }
            else
            {
                pos += ledgeDir * dirOffset;
            }
            Ray        ray = new Ray(pos, target.forward);
            RaycastHit hit;
            int        mask   = character.layers;
            float      radius = character.capsule.radius * 0.38f;
            float      dist   = limbIK.hangCheckDistance + 0.25f;

            if (Physics.SphereCast(ray, radius, out hit, dist, mask))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 5
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;
            }
            if (limbsIK && enableCatchIK)
            {
                limbsIK.setIKDirection(false);
                limbsIK.OnReachZeroRH = () =>
                {
                    limbsIK.RHandIKEnabled = false;
                    limbsIK.OnReachZeroRH  = null;
                };
            }
            character.triggerRootMotion = false;
            character.disableMove       = false;
            character.enablePhysics();
            character.animator.SetBool(HashIDs.JumpOnBool, false);
        }
Esempio n. 6
0
        bool _createTPCharacter()
        {
            TPCharacter tpcharacter = character.GetComponent <TPCharacter>();

            if (!tpcharacter)
            {
                tpcharacter = Undo.AddComponent <TPCharacter>(character);
            }

            // for some reason unity dont recognize 'Default' layer in ' GetMask' method so i must add it after
            tpcharacter.layers  = LayerMask.GetMask(/*"Default",*/ "DefaultNoCam", "DefaultSlope", "Walkable");
            tpcharacter.layers |= 1 << LayerMask.NameToLayer("Default");

            tpcharacter.movingTurnSpeed     = 360.0f;
            tpcharacter.stationaryTurnSpeed = 180.0f;
            tpcharacter.jumpPower           = 7.0f;
            tpcharacter.gravityMultiplier   = 2.0f;
            tpcharacter.moveSpeedMultiplier = 1.0f;
            tpcharacter.groundCheckDistance = 0.35f;
            tpcharacter.airSpeed            = 6.0f;
            tpcharacter.airControl          = 2.0f;
            tpcharacter.AnimatorSpeed       = 1.0f;
            tpcharacter.ledgeSpeed          = 3.0f;
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// early exit conditions
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <returns>condition</returns>
        public override bool condition(TPCharacter character)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }
            if (turnToLedge)
            {
                Vector3 charDir   = character.transform.forward;
                Vector3?closest   = closestPoint(character.transform.position);
                Vector3 direction = (closest.Value - character.transform.position);
                direction.y = 0.0f;
                direction.Normalize();
                float angle          = Vector3.Angle(charDir, direction);
                bool  lookingTowards = angle <= angleCondition;
                m_ConditionPassed = character.isGroundMode && lookingTowards;
            }
            else
            {
                bool lookingTowards = base.condition(character);
                m_ConditionPassed = character.isGroundMode && lookingTowards;
            }
            return(m_ConditionPassed);
        }
Esempio n. 8
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();
            }
        }
        /// <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;
            }

            // reset steps audio clips to character
            character.audioManager.ladderClips = null;
            character.triggerRootMotion        = false;
            character.disableMove = false;
            character.enablePhysics();
            if (GoingUp)
            {
                character.animator.SetBool(/*"pLadderUp"*/ HashIDs.LadderUpBool, false);
            }
            else
            {
                character.animator.SetBool(/*"pLadderDown"*/ HashIDs.LadderDownBool, false);
            }

            Vector3 right = character.transform.right;
            character.transform.up    = Vector3.up;
            character.transform.right = right;

            if (limbsIK)
            {
                limbsIK.handIKMode = IKMode.Default;
                limbsIK.feetIKMode = IKMode.Default;
                limbsIK.setIKDirection(false);

                limbsIK.OnReachZeroLH = () =>
                {
                    limbsIK.LHandIKEnabled = false;
                    limbsIK.OnReachZeroLH  = null;
                };
                limbsIK.OnReachZeroRH = () =>
                {
                    limbsIK.RHandIKEnabled = false;
                    limbsIK.OnReachZeroRH  = null;
                };
                limbsIK.LFootIKEnabled = false;
                limbsIK.RFootIKEnabled = false;
            }
        }
        private TPCharacter character = null;    // game character reference

        /// <summary>
        /// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        /// </summary>
        /// <param name="animator"></param>
        /// <param name="stateInfo"></param>
        /// <param name="layerIndex"></param>
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            if (character == null)
            {
                character = animator.transform.GetComponent <TPCharacter>();
            }
            if (character != null)
            {
                character.turnToDiveRollDIrection();
            }
        }
        /// <summary>
        /// get display info text
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <returns></returns>
        public override string get_info_text(TPCharacter character)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" +" < " + this.ToString() + ">");
#endif
                return "ERROR";
            }
            if (m_ConditionPassed)
                return "Press 'Use' to jump down";
            return "";
        }
        /// <summary>
        /// early exit conditions
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <returns>condition</returns>
        public override bool condition(TPCharacter character)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" +" < " + this.ToString() + ">");
#endif
                return false;
            }
            bool lookingTowards = base.condition(character);
            m_ConditionPassed = character.isGroundMode && lookingTowards;
            return m_ConditionPassed;
        }
        /// <summary>
        /// executes on match target start
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbsIK">ik helper</param>
        public override void onMatchTargetStart(TPCharacter character, IKHelper limbsIK)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" +" < " + this.ToString() + ">");
#endif
                return;
            }
            character.disablePhysics(true, false, false);
            m_TriggerInfo.doRotationToTarget = false; 
            m_TriggerInfo.rot_time = 0.0f;
            base.onMatchTargetStart(character, limbsIK);
        }
Esempio n. 14
0
        /// <summary>
        /// get display info text
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <returns>returns info string</returns>
        public virtual string get_info_text(TPCharacter character)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return("ERROR");
            }
            if (m_ConditionPassed)
            {
                return("Press 'Use'");
            }
            return("");
        }
Esempio n. 15
0
    void Start()
    {
        base.Start();

        if (Camera.main != null)
        {
            m_Cam = Camera.main.transform;
        }
        else
        {
            Debug.LogWarning(
                "Warning: no main camera found. Third person character needs a Camera tagged \"MainCamera\", for camera-relative controls.", gameObject);
        }

        m_Character = GetComponent <TPCharacter>();
    }
Esempio n. 16
0
        /// <summary>
        /// Custom On Scene GUI
        /// </summary>
        protected virtual void OnSceneGUI()
        {
            TPCharacter          _TPCharacter      = (TPCharacter)target;
            TPCInverseKinematics inverseKinematics = _TPCharacter.GetInverseKinematics();

            if (debugFootIK)
            {
                if (inverseKinematics.LeftFootPivot == null && inverseKinematics.RightFootPivot == null)
                {
                    return;
                }

                Handles.color = Color.black;
                Handles.DrawLine(inverseKinematics.LeftFootPivot.transform.position, inverseKinematics.LeftFootPivot.transform.position - Vector3.up * inverseKinematics.RayRange);
                Handles.DrawWireArc(inverseKinematics.LeftFootPivot.transform.position - Vector3.up * inverseKinematics.RayRange, Vector3.up, Vector3.forward, 360, 0.03f);
                Handles.color = new Color(0.25f, 0.25f, 0.25f, 0.1f);
                Handles.DrawSolidArc(inverseKinematics.LeftFootPivot.transform.position - Vector3.up * inverseKinematics.RayRange, Vector3.up, Vector3.forward, 360, 0.03f);

                Handles.color = Color.black;
                Handles.DrawLine(inverseKinematics.RightFootPivot.transform.position, inverseKinematics.RightFootPivot.transform.position - Vector3.up * inverseKinematics.RayRange);
                Handles.DrawWireArc(inverseKinematics.RightFootPivot.transform.position - Vector3.up * inverseKinematics.RayRange, Vector3.up, Vector3.forward, 360, 0.03f);
                Handles.color = new Color(0.25f, 0.25f, 0.25f, 0.1f);
                Handles.DrawSolidArc(inverseKinematics.RightFootPivot.transform.position - Vector3.up * inverseKinematics.RayRange, Vector3.up, Vector3.forward, 360, 0.03f);
            }

            if (debugUpperBodyIK)
            {
                Animator animator = _TPCharacter.GetComponent <Animator>();
                if (animator == null)
                {
                    return;
                }

                Transform head  = animator.GetBoneTransform(HumanBodyBones.Head);
                Transform spine = animator.GetBoneTransform(HumanBodyBones.Spine);

                Vector3 startPos = Extensions.CenterOfVectors(head.position, spine.position);

                if (inverseKinematics.LookTarget != null)
                {
                    Handles.color = Color.black;
                    Handles.DrawLine(startPos, inverseKinematics.LookTarget.position);
                }
            }
        }
Esempio n. 17
0
    private void Start()
    {
        // get the transform of the main camera
        if (Camera.main != null)
        {
            m_Cam = Camera.main.transform;
            print ("camera exists");
        }
        else
        {
            Debug.LogWarning(
                "Warning: no main camera found. Third person character needs a Camera tagged \"MainCamera\", for camera-relative controls.");
            // we use self-relative controls in this case, which probably isn't what the user wants, but hey, we warned them!
        }

        // get the third person character ( this should never be null due to require component )
        m_Character = GetComponent<TPCharacter>();
    }
        private bool m_Initialized     = false;      // is compoentn initialized ?


        /// <summary>
        /// initialize component
        /// </summary>
        public void initialize()
        {
            if (m_Initialized)
            {
                return;
            }
            m_Character = GetComponent <TPCharacter>();
            if (!m_Character)
            {
                Debug.LogError("Cannot find component 'TPCharacter'! " + " < " + this.ToString() + ">"); return;
            }
            m_Character.initialize();
            m_defines = GameObject.FindObjectOfType <Predefines>();
            if (!m_defines)
            {
                Debug.LogError("Cannot find component 'Predefines'." + " < " + this.ToString() + ">"); return;
            }
            m_Initialized = true;
        }
Esempio n. 19
0
        /// <summary>
        /// early exit conditions
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <returns>condition</returns>
        public virtual bool condition(TPCharacter character)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">");
#endif
                return(false);
            }
            m_ConditionPassed = false;
            Vector3 charDir = character.transform.forward;
            Vector3 thisDir = transform.forward;
            float   angle   = Vector3.Angle(charDir, thisDir);
            if (angle <= angleCondition)
            {
                m_ConditionPassed = true;
            }
            return(m_ConditionPassed);
        }
 /// <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 (use)
     {
         IGameCharacter icharacter = character.GetComponent <IGameCharacter>();
         if (icharacter != null)
         {
             icharacter.setNewItem(item);
         }
     }
     if (secondaryUse)
     {
         IGameCharacter icharacter = character.GetComponent <IGameCharacter>();
         if (icharacter != null)
         {
             icharacter.setSecondaryItem(item);
         }
     }
     return(false);
 }
        /// <summary>
        /// get display info text
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <returns></returns>
        public override string get_info_text(TPCharacter character)
        {
#if DEBUG_INFO
            if (!item)
            {
                Debug.LogError("Item missing < " + this.ToString() + " >");
                return("ERROR");
            }
#endif


            if (item is MeleeWeaponItem && (item as MeleeWeaponItem).itemType == InventoryItemType.Weapon1H)
            {
                return("Press 'E' to pick as primary weapon or 'F' as secondary weapon ( " + item.itemName + " )");
            }
            else
            {
                return("Pick Up " + item.itemName);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// executes on match target start
        /// </summary>
        /// <param name="character">character interacting with trigger</param>
        /// <param name="limbsIK">ik helper</param>
        public virtual void onMatchTargetStart(TPCharacter character, IKHelper limbsIK)
        {
            if (!character)
            {
#if DEBUG_INFO
                Debug.LogError("object cannot be null. " + " < " + this.ToString() + ">");
#endif
                return;
            }
#if DEBUG_INFO
            if (!character.audioManager)
            {
                Debug.LogError("object cannot be null. " + " < " + this.ToString() + ">");
                return;
            }
#endif
            character.audioManager.playJumpSound();
            m_TriggerInfo.rot_time      = 0.0f;
            m_TriggerInfo.doMatchTarget = true;
            m_TriggerInfo.startRotation = character.transform.rotation;
        }
Esempio n. 23
0
        /// <summary>
        /// initilaize component
        /// </summary>
        public void initialize()
        {
            if (m_initialized)
            {
                return;
            }

            m_Character = GetComponent <TPCharacter>();
            if (!m_Character)
            {
                Debug.LogError("cannot find 'TPCharacter' component. " + " < " + this.ToString() + ">"); return;
            }
            m_Character.initialize();

            m_Player = GetComponent <Player>();
            if (!m_Player)
            {
                Debug.LogError("Cannot find 'Player' component. " + " < " + this.ToString() + ">"); return;
            }

            IKHelper ls = GetComponent <IKHelper>();

            if (ls)
            {
                if (ls.enabled)
                {
                    m_IKHelper = ls;
                }
            }

            if (!m_TriggerUI)
            {
                Debug.LogError("Trigger UI not assigned! " + " < " + this.ToString() + ">");
                return;
            }
            m_TriggerUI.text = "";

            m_initialized = true;
        }
        /// <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.enablePhysics();
            character.animator.SetBool(/*"pJumpDown"*/HashIDs.JumpDownBool, false);
        }
        /// <summary>
        /// initialize component
        /// </summary>
        public virtual void initialize()
        {
            if (m_Initialized)
            {
                return;
            }

            m_Character = GetComponent <TPCharacter>();
            if (!m_Character)
            {
                Debug.LogError("Cannot find component 'TPCharacter'" + " < " + this.ToString() + ">");
            }
            m_Character.initialize();

            m_Audio = GetComponent <AudioSource>();
            if (!m_Audio)
            {
                Debug.LogError("Cannot find component 'AudioSource'" + " < " + this.ToString() + ">");
            }
            footstepsUser = GetComponent <FootstepsAudioUser>();

            m_Initialized = true;
        }
Esempio n. 26
0
        bool _createTPCharacter()
        {
            TPCharacter tpcharacter = character.GetComponent <TPCharacter>();

            if (!tpcharacter)
            {
                tpcharacter = Undo.AddComponent <TPCharacter>(character);
            }
            if (CharacterType == CharacterTypes.Default ||
                CharacterType == CharacterTypes.ThirdPerson)
            {
                // for some reason unity ( 5.2.2 ) dont recognize 'Default' layer in ' GetMask' method so i must add it after
                tpcharacter.layers  = LayerMask.GetMask(/*"Default", */ "DefaultNoCam", "DefaultSlope", "ColliderLayer");
                tpcharacter.layers |= 1 << LayerMask.NameToLayer("Default");
            }
            else if (CharacterType == CharacterTypes.TopDown)
            {
                // for some reason unity ( 5.2.2 ) dont recognize 'Default' layer in ' GetMask' method so i must add it after
                tpcharacter.layers  = LayerMask.GetMask(/*"Default",*/ "DefaultNoCam", "DefaultSlope", "ColliderLayer", "Walkable");
                tpcharacter.layers |= 1 << LayerMask.NameToLayer("Default");
            }

            tpcharacter.movingTurnSpeed     = 360.0f;
            tpcharacter.stationaryTurnSpeed = 180.0f;
            tpcharacter.jumpPower           = 7.0f;
            tpcharacter.gravityMultiplier   = 2.0f;
            tpcharacter.moveSpeedMultiplier = 1.0f;
            tpcharacter.groundCheckDistance = 0.35f;
            tpcharacter.airSpeed            = 6.0f;
            tpcharacter.airControl          = 2.0f;
            tpcharacter.AnimatorSpeed       = 1.0f;
            tpcharacter.ledgeSpeed          = 3.0f;
            tpcharacter.enableJumping       = enableJumping;
            tpcharacter.enableCrouching     = enableCrouching;
            return(true);
        }
Esempio n. 27
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);
        }
Esempio n. 28
0
 /// <summary>
 /// exit trigger
 /// </summary>
 /// <param name="character">character interacting with trigger</param>
 public virtual void exit(TPCharacter character)
 {
 }
        // initialize compoonent
        public void initialize()
        {
            if (m_Initialized)
            {
                return;
            }

            m_Character = GetComponent <TPCharacter>();
            if (!m_Character)
            {
                Debug.LogError("Cannot find 'TPCharacter' component." + " < " + this.ToString() + ">");
            }
            m_Character.initialize();

            if (!m_Character.animator.avatar.isHuman)
            {
                Debug.LogError("Not humanoid mecanim avatar!" + " < " + this.ToString() + ">");
                return;
            }
            if (!m_Character.animator.avatar.isValid)
            {
                Debug.LogError("Invalid mecanim avatar!" + " < " + this.ToString() + ">");
                return;
            }
            m_Animator = GetComponent <Animator>(); // m_Character.animator;
            if (!m_Animator)
            {
                Debug.LogError("Cannot find 'Animator' component");
            }


            Transform larm = m_Animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);

            if (!larm)
            {
                Debug.LogError("ANIMATOR ERROR ( IKHELPER )"); return;
            }
            Transform lelbow = m_Animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
            Transform lhand  = m_Animator.GetBoneTransform(HumanBodyBones.LeftHand);
            Transform lleg   = m_Animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
            Transform lknee  = m_Animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
            Transform lfoot  = m_Animator.GetBoneTransform(HumanBodyBones.LeftFoot);

            float armelb  = Vector3.Distance(larm.position, lelbow.position);
            float elbhand = Vector3.Distance(lelbow.position, lhand.position);

            m_ArmReach = armelb + elbhand;

            float hipknee  = Vector3.Distance(lleg.position, lknee.position);
            float kneefoot = Vector3.Distance(lknee.position, lfoot.position);

            m_LegReach = hipknee + kneefoot;

            Transform rarmup = m_Character.animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
            Transform relb   = m_Character.animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
            Transform rhand  = m_Character.animator.GetBoneTransform(HumanBodyBones.RightHand);

            float diff1 = Vector3.Distance(rarmup.position, relb.position);
            float diff2 = Vector3.Distance(relb.position, rhand.position);

            m_ArmReach = diff1 + diff2;

            m_Initialized = true;
        }
Esempio n. 30
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>
 /// end trigger animations
 /// NOTE: Does nothing on ItemTrigger
 /// </summary>
 /// <param name="character">character interacting with trigger</param>
 /// <param name="limbsIK">ik helper</param>
 public override void end(TPCharacter character, IKHelper limbsIK)
 {
 }