Exemple #1
0
 /// <summary>
 /// Returns the if the Next or Current Animator State is tagged: tag
 /// </summary>
 public virtual bool RealAnimatorState(string tag, int layerIndex = 0)
 {
     if (layerIndex == 0)
     {
         return(NextAnimState.IsTag(tag) || CurrentAnimState.IsTag(tag));
     }
     else
     {
         return(Anim.GetNextAnimatorStateInfo(layerIndex).IsTag(tag) || Anim.GetCurrentAnimatorStateInfo(layerIndex).IsTag(tag));
     }
 }
        ///──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        /// <summary>
        /// Fall Logic
        /// </summary>
        protected virtual void Falling()
        {
            //Don't Calcultate Fall Ray if the animal on any of these states
            if (CurrentAnimState.IsTag("Idle"))
            {
                return;
            }
            if (CurrentAnimState.IsTag("Sleep"))
            {
                return;
            }
            if (CurrentAnimState.IsTag("Action"))
            {
                return;
            }

            RaycastHit hitpos;

            float Multiplier = _Chest.multiplier * scaleFactor;

            if (CurrentAnimState.IsTag("Jump") || CurrentAnimState.IsTag("Fall"))
            {
                Multiplier *= FallRayMultiplier;
            }

            //Set the Fall Ray a bit farther from the front feet.



            _fallVector = _Chest.GetPivot +
                          (_transform.forward.normalized * (Shift ? GroundSpeed + 1 : GroundSpeed) * FallRayDistance * ScaleFactor);

            if (debug)
            {
                Debug.DrawRay(_fallVector, -transform.up * Multiplier, Color.magenta);
            }

            if (Physics.Raycast(_fallVector, -_transform.up, out hitpos, Multiplier, GroundLayer))
            {
                fall = false;
                if (Vector3.Angle(hitpos.normal, UpVector) > maxAngleSlope && isJumping())
                {
                    fall = true;                                                                        //if the ray found ground but is to Sloppy
                }
            }
            else
            {
                fall = true;
            }
        }
        /// <summary>
        /// This will check is the Animal is in any Jump State
        /// </summary>
        /// <param name="normalizedTime">The normalized time of the Jump Animation</param>
        /// <param name="half">True to check if is the First Half, False to check the Second Half</param>
        /// <returns></returns>
        public virtual bool isJumping(float normalizedTime, bool half)
        {
            if (half)  //if is jumping the first half
            {
                if (CurrentAnimState.IsTag("Jump"))
                {
                    if (CurrentAnimState.normalizedTime <= normalizedTime)
                    {
                        return(true);
                    }
                }

                if (NextAnimState.IsTag("Jump"))  //if is transitioning to jump
                {
                    if (NextAnimState.normalizedTime <= normalizedTime)
                    {
                        return(true);
                    }
                }
            }
            else //if is jumping the second half
            {
                if (CurrentAnimState.IsTag("Jump"))
                {
                    if (CurrentAnimState.normalizedTime >= normalizedTime)
                    {
                        return(true);
                    }
                }

                if (NextAnimState.IsTag("Jump"))  //if is transitioning to jump
                {
                    if (NextAnimState.normalizedTime >= normalizedTime)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        ///─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        /// <summary>
        /// Add more Rotations to the current Turn Animations
        /// </summary>
        protected virtual void AdditionalTurn()
        {
            float Turn;

            Turn = TurnSpeed;

            if (!CurrentAnimState.IsTag("Locomotion"))
            {
                Turn = 0;
            }

            if (swim)
            {
                Turn = swimSpeed;
            }

            if (movementAxis.z >= 0)
            {
                _transform.Rotate(_transform.up, Turn * 3 * movementAxis.x * Time.deltaTime);
            }
            else
            {
                _transform.Rotate(_transform.up, Turn * 3 * -movementAxis.x * Time.deltaTime);
            }

            if (isJumping() || fall && (!fly && !swim && !stun && !RealAnimatorState("Action")))               //More Rotation when jumping and falling... in air rotation
            {
                if (movementAxis.z >= 0)
                {
                    _transform.Rotate(_transform.up, 100 * movementAxis.x * Time.deltaTime);
                }
                else
                {
                    _transform.Rotate(_transform.up, 100 * -movementAxis.x * Time.deltaTime);
                }
            }
        }
 /// <summary>
 /// Returns the if the Next or Current Animator State is tagged: tag
 /// </summary>
 public virtual bool RealAnimatorState(string tag)
 {
     return(NextAnimState.IsTag(tag) || CurrentAnimState.IsTag(tag));
 }