/// <summary>
 /// Allows the motion to modify the ground and support information
 /// </summary>
 /// <param name="rState">Current state whose support info can be modified</param>
 /// <returns>Boolean that determines if the avatar is grounded</returns>
 public virtual bool DetermineGrounding(ref ControllerState rState)
 {
     return rState.IsGrounded;
 }
Esempio n. 2
0
        /// <summary>
        /// Allows the motion to modify the ground and support information
        /// </summary>
        /// <param name="rState">Current state whose support info can be modified</param>
        /// <returns>Boolean that determines if the avatar is grounded</returns>
        public override bool DetermineGrounding(ref ControllerState rState)
        {
            // These values need to be updated in LateUpdateMotion to have the
            // most accurate values. However, they will work here to help
            // modify things like root motion.
            rState.Support = mClimbable;
            rState.SupportPosition = mClimbable.transform.position;
            rState.SupportRotation = mClimbable.transform.rotation;
            if (rState.Support != mController.PrevState.Support || rState.SupportContactPosition.sqrMagnitude == 0f)
            {
                // This is set for the avatar
                rState.SupportContactPosition = mAvatarContactPosition;
            }

            return rState.IsGrounded;
        }
Esempio n. 3
0
 /// <summary>
 /// Allows the motion to modify the ground and support information
 /// </summary>
 /// <param name="rState">Current state whose support info can be modified</param>
 /// <returns>Boolean that determines if the avatar is grounded</returns>
 public override bool DetermineGrounding(ref ControllerState rState)
 {
     // If we've just started the jump, force the grounded flag off
     if (mIsActive && mPhase == Jump.PHASE_START_JUMP)
     {
         return false;
     }
     else
     {
         return rState.IsGrounded;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Sets the value of this state with values from another
        /// 
        /// Note: When the shift occurs, all intrinsict types (float, string, etc)
        /// have thier values copied over. Any reference types (arrays, objects) have
        /// thier references assigned. This includes 'child' properties.
        /// 
        /// For the reference values... if we want them shared between the prev and current
        /// instances, we don't need to do anything.
        /// 
        /// However, if we want reference values to be independant between the prev and current
        /// we need to grab the prev's reference, hold it, and then reset it.
        /// </summary>
        /// <param name="rSource">ControllerState that has the data to copy</param>
        public static void Shift(ref ControllerState rCurrent, ref ControllerState rPrev)
        {
            // Reference objects need to be held onto otherwise our 'prev' 
            // container will actually hold the reference in the 'current' container
            AnimatorLayerState[] lAnimatorStates = rPrev.AnimatorStates;

            // Move the current contents into the previous bucket
            rPrev = rCurrent;

            // Update the members of the states array. We have to do this
            // so 'prev' doesn't accidentally hold a reference sot the array in 'current'
            rPrev.AnimatorStates = lAnimatorStates;
            if (rPrev.AnimatorStates != null)
            {
                int lCount = lAnimatorStates.Length;
                for (int i = 0; i < lCount; i++)
                {
                    //rPrev.AnimatorStates[i] = rCurrent.AnimatorStates[i];

                    //TT
                    rPrev.AnimatorStates[i].MotionPhase = rCurrent.AnimatorStates[i].MotionPhase;
                    rPrev.AnimatorStates[i].AutoClearMotionPhase = rCurrent.AnimatorStates[i].AutoClearMotionPhase;
                    rPrev.AnimatorStates[i].StateInfo = rCurrent.AnimatorStates[i].StateInfo;
                    rPrev.AnimatorStates[i].TransitionInfo = rCurrent.AnimatorStates[i].TransitionInfo;
                }
            }

            // Initialize the object we're attached to. Don't clear
            // the contact position as we'll store it for future use
            rCurrent.Support = null;
            rCurrent.SupportPosition = Vector3.zero;
            rCurrent.SupportRotation = Quaternion.identity;

            // Initialize the ground information
            rCurrent.IsGrounded = false;
            rCurrent.GroundAngle = 0f;
            rCurrent.GroundNormal = Vector3.up;
            rCurrent.GroundDistance = float.MaxValue;
        }
Esempio n. 5
0
        /// <summary>
        /// Update the animator with data from the current state
        /// </summary>
        /// <param name="rState">ControllerState containing the current data</param>
        private void SetAnimatorProperties(ControllerState rState, bool rUseTrendData)
        {
            if (mAnimator == null) { return; }

            // The primary 'mode' the character is in
            mAnimator.SetInteger("Stance", rState.Stance);

            // The relative speed magnitude of the character (0 to 1)
            // Delay a bit before we update the speed if we're accelerating
            // or decelerating.
            mMecanimUpdateDelay -= Time.deltaTime;
            if (!rUseTrendData || mMecanimUpdateDelay <= 0f)
            {
                mAnimator.SetFloat("Input Magnitude", rState.InputMagnitudeTrend.Value); //, 0.05f, Time.deltaTime);
            }

            // The magnituded averaged out over the last 10 frames
            mAnimator.SetFloat("Input Magnitude Avg", rState.InputMagnitudeTrend.Average);

            // Direction of the input relative to the avatar's forward (-180 to 180)
            mAnimator.SetFloat("Input Angle From Avatar", rState.InputFromAvatarAngle); //, 0.15f, Time.deltaTime);

            // Direction of the input relative to the camera's forward (-180 to 180)
            mAnimator.SetFloat("Input Angle From Camera", rState.InputFromCameraAngle); //, 0.15f, Time.deltaTime); //, 0.05f, Time.deltaTime);

            // The raw input from the UI
            mAnimator.SetFloat("Input X", rState.InputX, 0.15f, Time.deltaTime);
            mAnimator.SetFloat("Input Y", rState.InputY, 0.15f, Time.deltaTime);

            // Motion phase per layer. Layer index is identified as "L0", "L1", etc.
            for (int i = 0; i < rState.AnimatorStates.Length; i++)
            {
                mAnimator.SetInteger("L" + i.ToString() + " Motion Phase", rState.AnimatorStates[i].MotionPhase);

                // By default, transitions are atomic. That means we can't interrupt one. 
                // Therefore, we will wait for any transitions to complete before we set the motion phase
                // on the Animator. Otherwise, the new value could get ignored by the Animator
                if (rState.AnimatorStates[i].AutoClearMotionPhase && rState.AnimatorStates[i].TransitionInfo.nameHash == 0)
                {
                    rState.AnimatorStates[i].MotionPhase = 0;
                }
            }
        }
        /// <summary>
        /// Allows the motion to modify the ground and support information
        /// </summary>
        /// <param name="rState">Current state whose support info can be modified</param>
        /// <returns>Boolean that determines if the avatar is grounded</returns>
        public virtual bool DetermineGrounding(ref ControllerState rState)
        {
            if (mActiveMotion != null)
            {
                return mActiveMotion.DetermineGrounding(ref rState);
            }

            return rState.IsGrounded;
        }