Exemple #1
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            // When falling, we don't want to change the camera mode. However,
            // the deactivate of the 'jump' will set it back. So we need to save the
            // current mode.
            if (mController.UseInput && mController.CameraRig != null)
            {
                mSavedCameraMode = mController.CameraRig.Mode;
            }

            // Flag the motion as active
            mIsActive = true;
            mIsActivatedFrame = true;
            mIsStartable = false;
            mLaunchForward = mController.transform.forward;

            mPhase = Fall.PHASE_START_FALL;
            mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, Fall.PHASE_START_FALL, true);

            // Remove any accumulated velocity so that gravity can start over
            mController.AccumulatedVelocity = new Vector3(mController.AccumulatedVelocity.x, 0f, mController.AccumulatedVelocity.z);

            // Set the ground velocity so that we can keep momentum going
            ControllerState lState = mController.State;
            lState.GroundLaunchVelocity = (mController.transform.rotation * mController.RootMotionVelocityAvg.Average);

            // Set the controller state with the modified values
            mController.State = lState;

            // Report that we're good to enter the jump
            return true;
        }
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public virtual bool Activate(MotionControllerMotion rPrevMotion)
        {
            // Flag the motion as active
            mIsActive = true;
            mIsActivatedFrame = true;
            mIsStartable = false;

            // Report that we're good enter the motion
            return true;
        }
Exemple #3
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            // Ensure we have good collision info
            if (sCollisionInfo.collider == null) { return false; }

            // Flag the motion as active
            mIsActive = true;
            mIsActivatedFrame = true;
            mIsStartable = false;
            //mHasArrived = false;
            //mArrivalLerp = 0.25f;

            mController.AccumulatedVelocity = Vector3.zero;

            // Set the control state
            ControllerState lState = mController.State;

            mPhase = ClimbMid.PHASE_START;
            mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, ClimbMid.PHASE_START, true);

            mController.State = lState;

            // Track the object we're trying to climb and store it
            mClimbable = sCollisionInfo.collider.gameObject;
            UnityEngine.Physics.IgnoreCollision(mController.CharController.collider, mClimbable.collider, true);

            // Set the grab position we're anchoring on
            mGrabPosition = sCollisionInfo.point;
            mLocalGrabPosition = Quaternion.Inverse(mClimbable.transform.rotation) * (sCollisionInfo.point - mClimbable.transform.position);

            // Set the grab normal coming out of the wall we're anchoring on
            mGrabPositionNormal = sCollisionInfo.normal;

            // Determine the target position given the grab info
            mTargetPosition = DetermineTargetPositions(ref mGrabPosition, ref mGrabPositionNormal);

            // Clear the avatar contact position so it can be reset
            mAvatarContactPosition = Vector3.zero;

            // Return
            return true;
        }
Exemple #4
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {

			// Store the last camera mode and force it to a fixed view.
			// We do this to always keep the camera behind the player
			if (mController.UseInput && mController.CameraRig != null)
			{
				mSavedCameraMode = mController.CameraRig.Mode;				
				mController.CameraRig.TransitionToMode(EnumCameraMode.CRAWLING);
			}

            // Force the character's stance to change
            mController.Stance = EnumControllerStance.SNEAK;

			mLaunchForward = mController.transform.forward;
			mController.SetColliderHeightAtBase(0.5f*mController.BaseColliderHeight);
//			mController.SetColliderRadiusAtCenter(2f*mController.BaseColliderRadius);

            // Trigger the change in the animator
            mController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, Sneak.PHASE_START, true);

            // Allow the base to finish
            return base.Activate(rPrevMotion);
        }
Exemple #5
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            mHasEnteredState = false;

            // Force the character's stance to change
            mController.Stance = EnumControllerStance.SNEAK;

            // Trigger the change in the animator
            mController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, Sneak.PHASE_START, true);

            // Allow the base to finish
            return base.Activate(rPrevMotion);
        }
Exemple #6
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            // Force the camera so we can do side jumps
            if (mController.UseInput && mController.CameraRig != null)
            {
                mSavedCameraMode = mController.CameraRig.Mode;
                mController.CameraRig.TransitionToMode(EnumCameraMode.THIRD_PERSON_FIXED);
            }

            // Flag the motion as active
            mIsActive = true;
            mIsActivatedFrame = true;
            mIsStartable = false;
            mLaunchForward = mController.transform.forward;

            // Initialize the jump
            mPhase = Jump.PHASE_START_JUMP;
            mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, Jump.PHASE_START_JUMP, true);

            // Remove any accumulated velocity so that gravity can start over
            mController.AccumulatedVelocity = new Vector3(mController.AccumulatedVelocity.x, 0f, mController.AccumulatedVelocity.z);

            // Set the ground velocity so that we can keep momentum going
            ControllerState lState = mController.State;
            lState.IsGrounded = false;
            lState.GroundLaunchVelocity = (mController.transform.rotation * mController.RootMotionVelocityAvg.Average);
            mController.State = lState;

            // Create the total impulse (direction + magnitude)
            Vector3 lImpulse = mController.transform.up * mImpulse;
            mController.AddImpulse(lImpulse);

            // Report that we're good to enter the jump
            return true;
        }
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            // Store the last camera mode and force it to a fixed view.
            // We do this to always keep the camera behind the player
            if (mController.UseInput && mController.CameraRig != null)
            {
                mController.CameraRig.TransitionToMode(EnumCameraMode.THIRD_PERSON_FOLLOW);
            }

            // It's possible we're activating from a small fall or other
            // skip while already in this motion. If so, no need to restart it.
            if (!IsInRunState)
            {
                // Trigger the change in the animator
                mController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, AdventureForward.PHASE_START, true);
            }

            return base.Activate(rPrevMotion);
        }
 /// <summary>
 /// Activate the specified motion (on the next frame).
 /// </summary>
 /// <param name="rMotion">Motion to activate</param>
 public void ActivateMotion(MotionControllerMotion rMotion)
 {
     if (rMotion != null)
     {
         rMotion.MotionLayer.QueueMotion(rMotion);
     }
 }
        /// <summary>
        /// Updates the motions tied to this layer at the variable
        /// time step (ie Update() not FixedUpdate().
        /// </summary>
        public void UpdateMotions()
        {
            int lPriorityIndex = int.MinValue;
            float lPriorityValue = float.MinValue;

            // Track how long the motion has been playing
            mActiveMotionDuration += Time.deltaTime;

            // Clean up the active motion's flag
            if (mActiveMotion != null) { mActiveMotion.IsActivatedFrame = false; }

            // First, check if our current motion is interruptible.
            // If it's not, we know we are simply running it.
            if (mActiveMotion == null || mActiveMotion.IsInterruptible)
            {
                bool lIsQueued = false;

                // Cycle through the motions to determine which ones were not
                // active and should be. We'll take the motion with the highest priority
                for (int i = 0; i < mMotions.Count; i++)
                {
                    // Clean up the activation flag
                    mMotions[i].IsActivatedFrame = false;

                    // Don't test if the motion is not enabled
                    if (!mMotions[i].IsEnabled) { continue; }

                    // If we haven't gone past the reactivation delay, move one
                    if (mMotions[i].ReactivationDelay > 0 && mMotions[i].DeactivationTime + mMotions[i].ReactivationDelay > Time.time) { continue; }

                    // If we're to force the motion, don't check others
                    if (mMotions[i].QueueActivation)
                    {
                        lIsQueued = true;

                        lPriorityIndex = i;
                        lPriorityValue = mMotions[i].Priority;

                        mMotions[i].QueueActivation = false;
                        break;
                    }
                    // Check for activation
                    else if (mMotions[i].IsStartable && mMotions[i].TestActivate())
                    {
                        if (lPriorityValue < mMotions[i].Priority)
                        {
                            lPriorityIndex = i;
                            lPriorityValue = mMotions[i].Priority;
                        }
                    }
                }

                // If we have a newly chosen motion, we need to activate it
                if (lPriorityIndex >= 0 && lPriorityIndex < mMotions.Count)
                {
                    // Ensure the motion will allow the interruption and
                    // shuts down as needed. If not, we cancel the upcoming motion.
                    if (!lIsQueued && mActiveMotion != null)
                    {
                        if (mActiveMotion.Priority > lPriorityValue)
                        {
                            lPriorityIndex = int.MinValue;
                        }
                        else if (!mActiveMotion.OnInterruption(mMotions[lPriorityIndex]))
                        {
                            lPriorityIndex = int.MinValue;
                        }
                    }

                    // Look to start the new motion
                    if (lPriorityIndex >= 0)
                    {
                        mMotions[lPriorityIndex].Activate(mActiveMotion);

                        if (mActiveMotion != null && mActiveMotion != mMotions[lPriorityIndex]) { mActiveMotion.Deactivate(); }
                        mActiveMotion = mMotions[lPriorityIndex];
                        mActiveMotionDuration = 0f;
                    }
                }
            }

            // Process any motions that are active. They will die out on thier own
            for (int i = 0; i < mMotions.Count; i++)
            {
                if (mMotions[i].IsActive)
                {
                    mMotions[i].UpdateMotion();

                    // As a safetly, test and set the active motion
                    if (mActiveMotion == null && mMotions[i].IsActive) 
                    {
                        mActiveMotion = mMotions[i];
                        mActiveMotionDuration = 0f;
                    }
                }
            }

            // Check if we've deactivated the current motion. If so, we
            // need to remove our reference to it
            if (mActiveMotion != null && !mActiveMotion.IsActive)
            {
                mActiveMotion = null;
                mActiveMotionDuration = 0f;
            }

            // Calculate the velocities of the active motions
            mAngularVelocity = Vector3.zero;
            mVelocity = Vector3.zero;

            for (int i = 0; i < mMotions.Count; i++)
            {
                if (mMotions[i].IsActive)
                {
                    mAngularVelocity += mMotions[i].AngularVelocity;
                    mVelocity += mMotions[i].Velocity;
                }
            }
        }
 /// <summary>
 /// Forces the motion to become active for the layer
 /// </summary>
 /// <param name="rLayerIndex">Layer to work with</param>
 /// <param name="rMotion">Motion to activate</param>
 /// <returns>Boolean used to determine if the motion was activated</returns>
 public bool QueueMotion(int rLayerIndex, MotionControllerMotion rMotion)
 {
     if (rLayerIndex >= MotionLayers.Count) { return false; }
     return MotionLayers[rLayerIndex].QueueMotion(rMotion);
 }
        /// <summary>
        /// Attempt to activate the specified motion and make it the 
        /// active motion.
        /// </summary>
        /// <param name="rMotion">Motion to activate</param>
        /// <returns>Determines if the motion was set as the active motion</returns>
        public bool QueueMotion(MotionControllerMotion rMotion)
        {
            if (!mMotions.Contains(rMotion)) { return false; }
            if (mActiveMotion == rMotion) { return false; }

            rMotion.QueueActivation = true;
            return true;
        }
        /// <summary>
        /// Removes the motion from the list of motions being managed
        /// </summary>
        /// <param name="rMotion">Motion to remove</param>
        public void RemoveMotion(MotionControllerMotion rMotion)
        {
            mMotions.Remove(rMotion);

            rMotion.Controller = null;
            rMotion.MotionLayer = null;
        }
        /// <summary>
        /// Adds a motion to the list of motions being managed
        /// </summary>
        /// <param name="rMotion">Motion to add</param>
        public void AddMotion(MotionControllerMotion rMotion)
        {
            if (!mMotions.Contains(rMotion))
            {
                rMotion.Controller = mController;
                rMotion.MotionLayer = this;

                mMotions.Add(rMotion);
            }
        }
 /// <summary>
 /// Raised when a motion is being interrupted by another motion
 /// </summary>
 /// <param name="rMotion">Motion doing the interruption</param>
 /// <returns>Boolean determining if it can be interrupted</returns>
 public virtual bool OnInterruption(MotionControllerMotion rMotion)
 {
     return true;
 }
Exemple #15
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            mYaw = 0f;
            mController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, CasualIdle.PHASE_START, true);

            return base.Activate(rPrevMotion);
        }
Exemple #16
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            // Store the last camera mode and force it to a fixed view.
            // We do this to always keep the camera behind the player
            if (mController.UseInput && mController.CameraRig != null)
            {
                mSavedCameraMode = mController.CameraRig.Mode;
                mController.CameraRig.TransitionToMode(EnumCameraMode.FIRST_PERSON);
            }

            // Force the character's stance to change
            mSavedStance = mController.Stance;
            mController.Stance = EnumControllerStance.COMBAT_RANGED;

            // Trigger the change in the animator
            mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, Walk360.PHASE_START, true);

            // Continue with the activation
            return base.Activate(rPrevMotion);
        }
Exemple #17
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            // Ensure we have good collision info
            if (sCollisionInfo.collider == null) { return false; }

            // Flag the motion as active
            mIsActive = true;
            mIsActivatedFrame = true;
            mIsStartable = false;
            mHasArrived = false;
            mArrivalLerp = 0.25f;

            mController.AccumulatedVelocity = Vector3.zero;

            // Set the control state
            ControllerState lState = mController.State;

            // Test if we're coming from a jump rise
            if (mGrabMotion == 1)
            {
                mPhase = ClimbCrouch.PHASE_FROM_JUMP_RISE;
                mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, ClimbCrouch.PHASE_FROM_JUMP_RISE);
            }
            // Test if we're coming from the top of the jump
            else if (mGrabMotion == 2)
            {
                mPhase = ClimbCrouch.PHASE_FROM_JUMP_TOP;
                mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, ClimbCrouch.PHASE_FROM_JUMP_TOP);
            }
            // Test if we're coming from a fall
            else if (mGrabMotion == 3)
            {
                mPhase = ClimbCrouch.PHASE_FROM_JUMP_FALL;
                mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, ClimbCrouch.PHASE_FROM_JUMP_FALL);
            }

            mController.State = lState;

            // Track the object we're trying to climb and store it
            mClimbable = sCollisionInfo.collider.gameObject;

            // Set the grab position we're anchoring on
            mGrabPosition = sCollisionInfo.point;
            mLocalGrabPosition = Quaternion.Inverse(mClimbable.transform.rotation) * (sCollisionInfo.point - mClimbable.transform.position);

            // Set the grab normal coming out of the wall we're anchoring on
            mGrabPositionNormal = sCollisionInfo.normal;

            // Determine the target position given the grab info
            mTargetPosition = DetermineTargetPositions(ref mGrabPosition, ref mGrabPositionNormal);

            // Clear the avatar contact position so it can be reset
            mAvatarContactPosition = Vector3.zero;

            // Return
            return true;
        }
Exemple #18
0
 /// <summary>
 /// Called to start the specific motion. If the motion
 /// were something like 'jump', this would start the jumping process
 /// </summary>
 /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
 public override bool Activate(MotionControllerMotion rPrevMotion)
 {
     mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, Slide.PHASE_START, true);
     return base.Activate(rPrevMotion);
 }
Exemple #19
0
        /// <summary>
        /// Called to start the specific motion. If the motion
        /// were something like 'jump', this would start the jumping process
        /// </summary>
        /// <param name="rPrevMotion">Motion that this motion is taking over from</param>
        public override bool Activate(MotionControllerMotion rPrevMotion)
        {
            mYaw = 0f;

            // Store the last camera mode and force it to a fixed view.
            // We do this to always keep the camera behind the player
            if (mController.UseInput && mController.CameraRig != null)
            {
                mController.CameraRig.TransitionToMode(EnumCameraMode.THIRD_PERSON_FIXED);
            }

            // Trigger the change in the animator
            mController.SetAnimatorMotionPhase(mAnimatorLayerIndex, SimpleForward.PHASE_START, true);

            // Continue with the activation
            return base.Activate(rPrevMotion);
        }