Exemplo n.º 1
0
        /// <summary>
        /// Called each frame that the action is active
        /// </summary>
        public override void Update()
        {
            if (!mIsShuttingDown)
            {
                bool lIsClicked = false;

                // Determine if we're done choosing a target
                if (mInputSource != null)
                {
                    // Check if we're cancelling
                    if (_CancelActionAlias.Length > 0 && mInputSource.IsJustPressed(_CancelActionAlias))
                    {
                        mSelectedPosition = Vector3Ext.Null;
                        mSelectedForward  = Vector3Ext.Null;

                        if (OnCancelledEvent != null)
                        {
                            OnCancelledEvent(this, mSelectedPosition);
                        }

                        Stop();
                    }
                    // Check if we're selecting
                    else if (mInputSource.IsJustPressed(_ActionAlias))
                    {
                        lIsClicked = true;
                    }
                }

                bool lRayHit = Raycast(!_UseMouse);

                if (lRayHit)
                {
                    ValidatePosition();
                }

                // Return the results
                if (lIsClicked)
                {
                    if (OnSelectedEvent != null)
                    {
                        OnSelectedEvent(this, mSelectedPosition);
                    }

                    Stop();
                }
            }

            // Handle the projectiles
            base.Update();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update is called every frame, if the MonoBehaviour is enabled.
        /// </summary>
        protected virtual void Update()
        {
            bool lTestInput = (WeaponSets != null && WeaponSets.Count > 0);

            if (lTestInput)
            {
                lTestInput = mMotionController.IsGrounded;
            }
            if (lTestInput)
            {
                lTestInput = IsEquipStoreAllowed;
            }

            if (_InputSource != null && _InputSource.IsEnabled && !mIsEquippingItem)
            {
                if (lTestInput && _UseNumberKeys)
                {
                    for (int i = 0; i < Mathf.Max(WeaponSets.Count, 8); i++)
                    {
                        if (_InputSource.IsJustPressed(KeyCode.Alpha1 + i))
                        {
                            lTestInput       = false;
                            _ActiveWeaponSet = i;
                            StartCoroutine(SwapWeaponSet(i));
                        }
                    }
                }

                if (lTestInput && _ToggleWeaponSetAlias.Length > 0)
                {
                    float lToggle = _InputSource.GetValue(_ToggleWeaponSetAlias);
                    if (lToggle != 0f)
                    {
                        lTestInput = false;
                        StartCoroutine(SwapWeaponSet(_ActiveWeaponSet));
                    }
                }

                if (lTestInput && _ShiftWeaponSetAlias.Length > 0)
                {
                    float lShift = _InputSource.GetValue(_ShiftWeaponSetAlias);
                    if (lShift != 0f)
                    {
                        _ActiveWeaponSet += (lShift < -0.1f ? -1 : (lShift > 0.1f ? 1 : 0));
                        if (_ActiveWeaponSet < 0)
                        {
                            _ActiveWeaponSet = WeaponSets.Count - 1;
                        }
                        else if (_ActiveWeaponSet >= WeaponSets.Count)
                        {
                            _ActiveWeaponSet = 0;
                        }

                        lTestInput = false;
                        StartCoroutine(SwapWeaponSet(_ActiveWeaponSet));
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Called every frame.
 /// </summary>
 protected void Update()
 {
     // Process input to do game level input
     if (_InputSource != null)
     {
         if (_ShowCursorAlias.Length > 0)
         {
             if (_InputSource.IsJustPressed(_ShowCursorAlias))
             {
                 IsCursorVisible = !IsCursorVisible;
             }
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Called every frame.
        /// </summary>
        protected void Update()
        {
            // Process input to do game level input
            if (_InputSource != null)
            {
#if UNITY_EDITOR
                if (_EditorPauseAlias.Length > 0)
                {
                    if (_InputSource.IsJustPressed(_EditorPauseAlias))
                    {
                        EditorApplication.isPaused = true;
                    }
                }
#endif

                if (_ShowCursorAlias.Length > 0)
                {
                    if (_InputSource.IsJustPressed(_ShowCursorAlias))
                    {
                        IsCursorVisible = !IsCursorVisible;
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Update is called every frame, if the MonoBehaviour is enabled.
        /// </summary>
        protected virtual void Update()
        {
            // Check if we should cast a spell
            if (_ActionAlias.Length > 0 && _InputSource != null && _DefaultSpellIndex > 0 && _DefaultSpellIndex < _Spells.Count)
            {
                if (_InputSource.IsJustPressed(_ActionAlias))
                {
                    bool lCast = false;

                    // Activate the spell through the motion
                    MotionController lMotionController = gameObject.GetComponent <MotionController>();
                    if (lMotionController != null)
                    {
                        PMP_BasicSpellCastings lCastMotion = lMotionController.GetMotion <PMP_BasicSpellCastings>();
                        if (lCastMotion != null)
                        {
                            lCast = true;
                            lMotionController.ActivateMotion(lCastMotion, _DefaultSpellIndex);
                        }
                    }

                    // If we couldn't activate the motion, activate the spell directly
                    if (!lCast)
                    {
                        InstantiateSpell(_DefaultSpellIndex);
                    }
                }
            }

            // Update each active spell
            for (int i = 0; i < _ActiveSpells.Count; i++)
            {
                _ActiveSpells[i].Update();
            }

            // Release the completed spells
            for (int i = _ActiveSpells.Count - 1; i >= 0; i--)
            {
                Spell lSpell = _ActiveSpells[i];
                if (lSpell.State == EnumSpellState.COMPLETED)
                {
                    lSpell.Release();
                    _ActiveSpells.RemoveAt(i);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called every frame so the driver can process input and
        /// update the actor controller.
        /// </summary>
        protected virtual void Update()
        {
            if (!_IsEnabled)
            {
                return;
            }
            if (mActorController == null)
            {
                return;
            }
            if (mInputSource == null || !mInputSource.IsEnabled)
            {
                return;
            }

            float lDeltaTime = TimeManager.SmoothedDeltaTime;

            // Rotate based on the mouse
            if (mInputSource.IsViewingActivated)
            {
                float      lYaw      = mInputSource.ViewX;
                Quaternion lRotation = Quaternion.Euler(0f, lYaw * mDegreesPer60FPSTick, 0f);

                mActorController.Rotate(lRotation);
            }

            // Move based on WASD
            Vector3 lInput    = new Vector3(mInputSource.MovementX, 0f, mInputSource.MovementY);
            Vector3 lMovement = lInput * _MovementSpeed * lDeltaTime;

            if (lMovement.sqrMagnitude > 0f)
            {
                mActorController.RelativeMove(lMovement);
            }

            // Jump based on space
            if (mInputSource.IsJustPressed("Jump"))
            {
                if (mActorController.State.IsGrounded)
                {
                    mActorController.AddImpulse(transform.up * _JumpForce);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Called every frame so the driver can process input and
        /// update the actor controller.
        /// </summary>
        protected virtual void Update()
        {
            // Ensure we have everything we need
            if (mActorController == null)
            {
                return;
            }
            if (mInputSource == null || !mInputSource.IsEnabled)
            {
                return;
            }

            // Initialize some variables
            Vector3    lMovement = Vector3.zero;
            Quaternion lRotation = Quaternion.identity;

            // -----------------------------------------------------------------
            // INPUT
            // -----------------------------------------------------------------

            // This is the horizontal movement of the mouse or Xbox controller's right stick
            //float lYaw = mInputSource.ViewX;

            // This is the WASD buttons or Xbox controller's left stick
            Vector3 lInput = new Vector3(mInputSource.MovementX, 0f, mInputSource.MovementY);


            // -----------------------------------------------------------------
            // ATTACH TO WALL
            // -----------------------------------------------------------------
            if (mIsInToWall)
            {
                Vector3 lToWallHit       = mToWallPoint - transform.position;
                float   lToWallHitNormal = Vector3.Angle(mActorController._Transform.up, mToWallNormal);

                // Move to the target and ensure we orient ourselves to the wall
                if (lToWallHit.magnitude > 0.03f || lToWallHitNormal > 0.5f)
                {
                    mActorController.SetTargetGroundNormal(mToWallNormal);

                    lMovement = lToWallHit.normalized * Mathf.Min(MovementSpeed * Time.deltaTime, lToWallHit.magnitude);
                    mActorController.Move(lMovement);
                }
                // Once we're there, clean up
                else
                {
                    mIsInToWall   = false;
                    mToWallPoint  = Vector3.zero;
                    mToWallNormal = Vector3.zero;

                    mActorController.MaxSlopeAngle       = mSavedMaxSlopeAngle;
                    mActorController.OrientToGroundSpeed = mSavedOrientToGroundSpeed;
                    mActorController.SetTargetGroundNormal(Vector3.zero);

                    // Disable gravity temporarily
                    mActorController.IsGravityEnabled     = true;
                    mActorController.FixGroundPenetration = true;
                }
            }
            else
            {
                // -----------------------------------------------------------------
                // ROTATE
                // -----------------------------------------------------------------

                // Set the target based on the input. This works because we're looking down
                // the world's z-axis.
                if (lInput.x < 0f)
                {
                    mTargetForward = Vector3.left;
                }
                else if (lInput.x > 0f)
                {
                    mTargetForward = Vector3.right;
                }

                // If we have a target forward start rotating towards it and ignore input
                if (mTargetForward.sqrMagnitude > 0f)
                {
                    // Determine how much we need to rotate to get to the target
                    float lTargetAngle = Vector3Ext.SignedAngle(mActorController.Yaw.Forward(), mTargetForward);

                    // If there is no difference, we can turn off the target
                    if (lTargetAngle == 0f)
                    {
                        mTargetForward = Vector3.zero;
                    }
                    else
                    {
                        // Grab the actual rotation angle based on our speed. However, make sure we don't overshoot the
                        // angle. So, we do this logic to truncate it if we're only a tiny bit off.
                        float lRotationAngle = Mathf.Sign(lTargetAngle) * Mathf.Min(RotationSpeed * Time.deltaTime, Mathf.Abs(lTargetAngle));

                        // Since the rotate function deals with the actor's yaw, we just to a vector3.up (it's
                        // relative to the actor regardless of his orientation/tilt
                        lRotation = Quaternion.AngleAxis(lRotationAngle, Vector3.up);

                        // Rotate.
                        mActorController.Rotate(lRotation);
                    }
                }

                // -----------------------------------------------------------------
                // MOVE
                // -----------------------------------------------------------------

                // We get the tilt so we can add this up/down direction to the camera input. This helps
                // characters to not run off ramps since they are moving how they are facing (ie down a ramp)
                // vs. simply forward (off the ramp)
                Quaternion lTilt = QuaternionExt.FromToRotation(Vector3.up, mActorController._Transform.up);

                // Move based on WASD we add the tilt
                lMovement = lTilt * lInput * MovementSpeed * Time.deltaTime;
                mActorController.Move(lMovement);

                // -----------------------------------------------------------------
                // JUMP
                // -----------------------------------------------------------------

                // Only jump if the button is pressed and we're on the ground
                if (mInputSource.IsJustPressed("Jump"))
                {
                    if (mActorController.State.IsGrounded)
                    {
                        mActorController.AddImpulse(mActorController._Transform.up * JumpForce);
                    }
                }

                // -----------------------------------------------------------------
                // TEST FOR WALL
                // -----------------------------------------------------------------

                RaycastHit lWallHitInfo;
                if (TestForWallCollision(lMovement, out lWallHitInfo) ||
                    TestForWallAt90DegreeDrop(lMovement, out lWallHitInfo))
                {
                    // Save the tilt values
                    mIsInToWall   = true;
                    mToWallPoint  = lWallHitInfo.point;
                    mToWallNormal = lWallHitInfo.normal;

                    // Save and reset some AC values that will help us to tilt
                    mSavedOrientToGroundSpeed            = mActorController.OrientToGroundSpeed;
                    mActorController.OrientToGroundSpeed = 0.75f;

                    mSavedMaxSlopeAngle            = mActorController.MaxSlopeAngle;
                    mActorController.MaxSlopeAngle = 0f;

                    // Disable gravity temporarily
                    mActorController.IsGravityEnabled     = false;
                    mActorController.FixGroundPenetration = false;
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Called every frame so the driver can process input and
        /// update the actor controller.
        /// </summary>
        protected virtual void Update()
        {
            // Ensure we have everything we need
            if (mActorController == null)
            {
                return;
            }
            if (mInputSource == null || !mInputSource.IsEnabled)
            {
                return;
            }

            // Initialize some variables
            Vector3    lMovement = Vector3.zero;
            Quaternion lRotation = Quaternion.identity;

            // -----------------------------------------------------------------
            // INPUT
            // -----------------------------------------------------------------

            // This is the horizontal movement of the mouse or Xbox controller's right stick
            float lYaw = mInputSource.ViewX;

            // This is the WASD buttons or Xbox controller's left stick
            Vector3 lInput = new Vector3(mInputSource.MovementX, 0f, mInputSource.MovementY);

            // -----------------------------------------------------------------
            // ROTATE
            // -----------------------------------------------------------------

            // If the input source says we can, rotate based on the yaw.
            if (mInputSource.IsViewingActivated)
            {
                // The input from the mouse already takes the frame rate into account. By doing
                // the multiplication here, we keep the rotation consistant across frame rates.
                lRotation = Quaternion.Euler(0f, lYaw * mDegreesPer60FPSTick, 0f);

                // Rotate our actor
                mActorController.Rotate(lRotation);
            }

            // -----------------------------------------------------------------
            // MOVE
            // -----------------------------------------------------------------

            // We get the tilt so we can add this up/down direction to the camera input. This helps
            // characters to not run off ramps since they are moving how they are facing (ie down a ramp)
            // vs. simply forward (off the ramp)
            Quaternion lTilt = QuaternionExt.FromToRotation(Vector3.up, mActorController._Transform.up);

            // Move based on WASD we add the tilt
            lMovement = lTilt * lInput * MovementSpeed * Time.deltaTime;
            mActorController.Move(lMovement);

            // -----------------------------------------------------------------
            // JUMP
            // -----------------------------------------------------------------

            // Only jump if the button is pressed and we're on the ground
            if (mInputSource.IsJustPressed("Jump"))
            {
                if (mActorController.State.IsGrounded)
                {
                    mActorController.AddImpulse(mActorController._Transform.up * JumpForce);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Called every frame to perform processing. We only use
        /// this function if it's not called by another component.
        /// </summary>
        protected void Update()
        {
            if (mAnimator == null)
            {
                return;
            }
            if (mCameraRig == null)
            {
                return;
            }
            if (Time.deltaTime == 0f)
            {
                return;
            }

            // Store the state we're in
            mStateInfo      = mAnimator.GetCurrentAnimatorStateInfo(0);
            mTransitionInfo = mAnimator.GetAnimatorTransitionInfo(0);

            if (mCameraRig.Mode == 2)
            {
                if (mStance != 2)
                {
                    mPrevStance = mStance;
                    mStance     = 2;
                }
            }
            else
            {
                if (mStance == 2)
                {
                    mStance = mPrevStance;
                }
            }

            // Determine the stance we're in
            if (mInputSource != null && mInputSource.IsPressed(KeyCode.LeftControl))
            {
                //if (mStance != 2)
                //{
                //    mPrevStance = mStance;
                //    mStance = 2;

                //    mPrevRigMode = CameraRigMode;

                //    // Start the transition process
                //    //_CameraRig.TransitionToMode(EnumCameraMode.FIRST_PERSON);
                //    CameraRigMode = EnumCameraMode.FIRST_PERSON;
                //}
            }
            else if (mStance == 2)
            {
                //mStance = mPrevStance;

                ////_CameraRig.TransitionToMode(mPrevRigMode);
                //CameraRigMode = mPrevRigMode;
            }
            else if (mInputSource != null && mInputSource.IsJustPressed(KeyCode.T))
            {
                mPrevStance = mStance;
                if (mStance == 0)
                {
                    mStance = 1;
                    ((AdventureRig)mCameraRig).AnchorOrbitsCamera = false;
                }
                else if (mStance == 1)
                {
                    mStance = 0;
                    ((AdventureRig)mCameraRig).AnchorOrbitsCamera = true;
                }

                mCameraRig.Mode = 0;
            }

            // Grab the direction and speed of the input relative to our current heading
            StickToWorldspace(this.transform, _CameraRig.transform, ref mTempState);

            // Ensure some of the other values are set correctly
            mTempState.Acceleration   = mState.Acceleration;
            mTempState.InitialHeading = mState.InitialHeading;

            // Ranged movement allows for slow forward, backwards, and strafing
            if (mStance == 2)
            {
                //CameraRigMode = EnumCameraMode.FIRST_PERSON;

                mTempState.Speed *= _TargetingStanceMovementSpeedMultiplier;

                // Change our heading if needed
                if (mTempState.Speed == 0)
                {
                    if (IsInBackwardsState)
                    {
                        mTempState.InitialHeading = 2;
                    }
                    else
                    {
                        mTempState.InitialHeading = 0;
                    }
                }
                else if (mTempState.Speed != 0 && mState.Speed == 0)
                {
                    float lInitialAngle = Mathf.Abs(mTempState.FromCameraAngle);
                    if (lInitialAngle < mForwardHeadingLimit)
                    {
                        mTempState.InitialHeading = 0;
                    }
                    else if (lInitialAngle > 180f - mBackwardsHeadingLimit)
                    {
                        mTempState.InitialHeading = 2;
                    }
                    else
                    {
                        mTempState.InitialHeading = 1;
                    }
                }

                // Ensure we're always facing forward
                //mYAxisRotationAngle = NumberHelper.GetHorizontalAngle(transform.forward, _CameraRig.transform.forward);
                //mTempState.FromAvatarAngle = 0f;
            }
            // Combat movement allows for forward, backwards, strafing, and pivoting
            else if (mStance == 1)
            {
                // Determine our initial heading
                if (mTempState.Speed == 0)
                {
                    if (IsInBackwardsState)
                    {
                        mTempState.InitialHeading = 2;
                    }
                    else
                    {
                        mTempState.InitialHeading = 0;
                    }
                }
                else if (mTempState.Speed != 0 && mState.Speed == 0)
                {
                    float lInitialAngle = Mathf.Abs(mTempState.FromCameraAngle);
                    if (lInitialAngle < mForwardHeadingLimit)
                    {
                        mTempState.InitialHeading = 0;
                    }
                    else if (lInitialAngle > 180f - mBackwardsHeadingLimit)
                    {
                        mTempState.InitialHeading = 2;
                    }
                    else
                    {
                        mTempState.InitialHeading = 1;
                    }
                }

                // Ensure if we've been heading forward that we don't allow the
                // avatar to rotate back facing the player
                if (mTempState.InitialHeading == 0)
                {
                    //CameraRigMode = EnumCameraMode.THIRD_PERSON_FOLLOW;

                    // Force the input to make us go forwards
                    if (mTempState.Speed > 0.1f && (mTempState.FromCameraAngle < -90 || mTempState.FromCameraAngle > 90))
                    {
                        mTempState.InputY = 1;
                    }

                    // If no forward rotation is allowed, this is easy
                    if (mForwardHeadingLimit == 0f)
                    {
                        mTempState.FromAvatarAngle = 0f;
                    }
                    // Respect the foward rotation limits
                    else
                    {
                        // Test if our rotation reaches the max from the camera. We use the camera since
                        // the avatar itself rotates and this limit is relative.
                        if (mTempState.FromCameraAngle < -mForwardHeadingLimit)
                        {
                            mTempState.FromCameraAngle = -mForwardHeadingLimit;
                        }
                        else if (mTempState.FromCameraAngle > mForwardHeadingLimit)
                        {
                            mTempState.FromCameraAngle = mForwardHeadingLimit;
                        }

                        // If we have reached a limit, we need to adjust the avatar angle
                        if (Mathf.Abs(mTempState.FromCameraAngle) == mForwardHeadingLimit)
                        {
                            // Flip the angle if we're crossing over the axis
                            if (Mathf.Sign(mTempState.FromCameraAngle) != Mathf.Sign(mState.FromCameraAngle))
                            {
                                mTempState.FromCameraAngle = -mTempState.FromCameraAngle;
                            }

                            // Only allow the avatar to rotate the heading limit, taking into account the angular
                            // difference between the camera and the avatar
                            mTempState.FromAvatarAngle = mTempState.FromCameraAngle + NumberHelper.GetHorizontalAngle(transform.forward, _CameraRig.transform.forward);
                        }
                    }
                }
                else if (mTempState.InitialHeading == 2)
                {
                    //CameraRigMode = EnumCameraMode.THIRD_PERSON_FIXED;

                    // Force the input to make us go backwards
                    if (mTempState.Speed > 0.1f && (mTempState.FromCameraAngle > -90 && mTempState.FromCameraAngle < 90))
                    {
                        mTempState.InputY = -1;
                    }

                    // Ensure we don't go beyond our boundry
                    if (mBackwardsHeadingLimit != 0f)
                    {
                        float lBackwardsHeadingLimit = 180f - mBackwardsHeadingLimit;

                        // Test if our rotation reaches the max from the camera. We use the camera since
                        // the avatar itself rotates and this limit is relative.
                        if (mTempState.FromCameraAngle <= 0 && mTempState.FromCameraAngle > -lBackwardsHeadingLimit)
                        {
                            mTempState.FromCameraAngle = -lBackwardsHeadingLimit;
                        }
                        else if (mTempState.FromCameraAngle >= 0 && mTempState.FromCameraAngle < lBackwardsHeadingLimit)
                        {
                            mTempState.FromCameraAngle = lBackwardsHeadingLimit;
                        }

                        // If we have reached a limit, we need to adjust the avatar angle
                        if (Mathf.Abs(mTempState.FromCameraAngle) == lBackwardsHeadingLimit)
                        {
                            // Only allow the avatar to rotate the heading limit, taking into account the angular
                            // difference between the camera and the avatar
                            mTempState.FromAvatarAngle = mTempState.FromCameraAngle + NumberHelper.GetHorizontalAngle(transform.forward, _CameraRig.transform.forward);
                        }

                        // Since we're moving backwards, we need to flip the movement angle.
                        // If we're not moving and simply finishing an animation, we don't
                        // want to rotate at all.
                        if (mTempState.Speed == 0)
                        {
                            mTempState.FromAvatarAngle = 0f;
                        }
                        else if (mTempState.FromAvatarAngle <= 0)
                        {
                            mTempState.FromAvatarAngle += 180f;
                        }
                        else if (mTempState.FromAvatarAngle > 0)
                        {
                            mTempState.FromAvatarAngle -= 180f;
                        }
                    }
                }
                else if (mTempState.InitialHeading == 1)
                {
                    //CameraRigMode = EnumCameraMode.THIRD_PERSON_FIXED;

                    // Move out of the sidestep if needed
                    if (mTempState.InputY > 0.1)
                    {
                        mTempState.InitialHeading = 0;
                    }
                    else if (mTempState.InputY < -0.1)
                    {
                        mTempState.InitialHeading = 2;
                    }

                    // We need to be able to rotate our avatar so it's facing
                    // in the direction of the camera
                    if (mTempState.InitialHeading == 1)
                    {
                        mTempState.FromCameraAngle = 0f;
                        mTempState.FromAvatarAngle = mTempState.FromCameraAngle + NumberHelper.GetHorizontalAngle(transform.forward, _CameraRig.transform.forward);
                    }
                }
            }

            // Determine the acceleration. We test this agains the 'last-last' speed so
            // that we are averaging out one frame.
            //mLastAcceleration = mAcceleration;
            mPrevState.Acceleration = mState.Acceleration;

            // Determine the trend so we can figure out acceleration
            if (mTempState.Speed == mState.Speed)
            {
                if (mSpeedTrendDirection != 0)
                {
                    mSpeedTrendDirection = 0;
                }
            }
            else if (mTempState.Speed < mState.Speed)
            {
                if (mSpeedTrendDirection != 1)
                {
                    mSpeedTrendDirection = 1;
                    if (mMecanimUpdateDelay <= 0f)
                    {
                        mMecanimUpdateDelay = 0.2f;
                    }
                }

                // Acceleration needs to stay consistant for mecanim
                mTempState.Acceleration = mTempState.Speed - mSpeedTrendStart;
            }
            else if (mTempState.Speed > mState.Speed)
            {
                if (mSpeedTrendDirection != 2)
                {
                    mSpeedTrendDirection = 2;
                    if (mMecanimUpdateDelay <= 0f)
                    {
                        mMecanimUpdateDelay = 0.2f;
                    }
                }

                // Acceleration needs to stay consistant for mecanim
                mTempState.Acceleration = mTempState.Speed - mSpeedTrendStart;
            }

            // Shuffle the states to keep us from having to reallocated
            AdventureControllerState lTempState = mPrevState;

            mPrevState = mState;
            mState     = mTempState;
            mTempState = lTempState;

            // Apply the movement and rotation
            ApplyMovement();
            ApplyRotation();

            // Delay a bit before we update the speed if we're accelerating
            // or decelerating.
            mMecanimUpdateDelay -= Time.deltaTime;
            if (mMecanimUpdateDelay <= 0f)
            {
                mAnimator.SetFloat("Speed", mState.Speed); //, 0.05f, Time.deltaTime);

                mSpeedTrendStart = mState.Speed;
            }

            // Update the direction relative to the avatar
            mAnimator.SetFloat("Avatar Direction", mState.FromAvatarAngle);

            // At this point, we never use angular speed. Rotation is done
            // in the ApplyRotation() function. Angular speed currently only effects
            // locomotion.
            mAnimator.SetFloat("Angular Speed", 0f);

            // The stance determins if we're in exploration or combat mode.
            mAnimator.SetInteger("Stance", mStance);

            // The direction from the camera
            mAnimator.SetFloat("Camera Direction", mState.FromCameraAngle); //, 0.05f, Time.deltaTime);

            // The raw input from the UI
            mAnimator.SetFloat("Input X", mState.InputX); //, 0.25f, Time.deltaTime);
            mAnimator.SetFloat("Input Y", mState.InputY); //, 0.25f, Time.deltaTime);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called every frame so the driver can process input and
        /// update the actor controller.
        /// </summary>
        protected virtual void Update()
        {
            // Ensure we have everything we need
            if (mActorController == null)
            {
                return;
            }
            if (mInputSource == null || !mInputSource.IsEnabled)
            {
                return;
            }

            // Initialize some variables
            Vector3    lMovement = Vector3.zero;
            Quaternion lRotation = Quaternion.identity;

            // -----------------------------------------------------------------
            // INPUT
            // -----------------------------------------------------------------

            // This is the horizontal movement of the mouse or Xbox controller's right stick
            //float lYaw = mInputSource.ViewX;

            // This is the WASD buttons or Xbox controller's left stick
            Vector3 lInput = new Vector3(mInputSource.MovementX, 0f, mInputSource.MovementY);

            // -----------------------------------------------------------------
            // ROTATE
            // -----------------------------------------------------------------

            // Set the target based on the input. This works because we're looking down
            // the world's z-axis.
            if (lInput.x < 0f)
            {
                mTargetForward = Vector3.left;
            }
            else if (lInput.x > 0f)
            {
                mTargetForward = Vector3.right;
            }

            // If we have a target forward start rotating towards it and ignore input
            if (mTargetForward.sqrMagnitude > 0f)
            {
                // Determine how much we need to rotate to get to the target
                float lTargetAngle = Vector3Ext.SignedAngle(mActorController.Yaw.Forward(), mTargetForward);

                // If there is no difference, we can turn off the target
                if (lTargetAngle == 0f)
                {
                    mTargetForward = Vector3.zero;
                }
                else
                {
                    // Grab the actual rotation angle based on our speed. However, make sure we don't overshoot the
                    // angle. So, we do this logic to truncate it if we're only a tiny bit off.
                    float lRotationAngle = Mathf.Sign(lTargetAngle) * Mathf.Min(RotationSpeed * Time.deltaTime, Mathf.Abs(lTargetAngle));

                    // Since the rotate function deals with the actor's yaw, we just to a vector3.up (it's
                    // relative to the actor regardless of his orientation/tilt
                    lRotation = Quaternion.AngleAxis(lRotationAngle, Vector3.up);

                    // Rotate.
                    mActorController.Rotate(lRotation);
                }
            }

            // -----------------------------------------------------------------
            // MOVE
            // -----------------------------------------------------------------

            // We get the tilt so we can add this up/down direction to the camera input. This helps
            // characters to not run off ramps since they are moving how they are facing (ie down a ramp)
            // vs. simply forward (off the ramp)
            Quaternion lTilt = QuaternionExt.FromToRotation(Vector3.up, mActorController._Transform.up);

            // Move based on WASD we add the tilt
            lMovement = lTilt * lInput * MovementSpeed * Time.deltaTime;
            mActorController.Move(lMovement);

            // -----------------------------------------------------------------
            // JUMP
            // -----------------------------------------------------------------

            // Only jump if the button is pressed and we're on the ground
            if (mInputSource.IsJustPressed("Jump"))
            {
                if (mActorController.State.IsGrounded)
                {
                    mActorController.AddImpulse(mActorController._Transform.up * JumpForce);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Update is called every frame, if the MonoBehaviour is enabled.
        /// </summary>
        protected virtual void Update()
        {
            if (mMotionController == null)
            {
                return;
            }

            if (mInputSource != null)
            {
                if (_IsLockingEnabled && _ToggleCombatantLockAlias.Length > 0)
                {
                    if (mInputSource.IsJustPressed(_ToggleCombatantLockAlias))
                    {
                        if (IsTargetLocked)
                        {
                            Target = null;
                        }
                        else
                        {
                            if (mActorStances == null || mActorStances.Count == 0 || mActorStances.Contains(mMotionController.Stance))
                            {
                                Target = FindTarget();
                            }
                        }
                    }
                }
            }

            // Unlock the target if our stance isn't valid
            if (_IsLockingEnabled && IsTargetLocked)
            {
                // Ensure our target is alive and able to be targeted
                if (_Target != null)
                {
                    ActorCore lTargetActorCore = _Target.GetComponent <ActorCore>();
                    if (lTargetActorCore != null && !lTargetActorCore.IsAlive)
                    {
                        IsTargetLocked = false;
                        OnTargetUnlocked(_Target);
                    }
                }

                // Ensure we're in a stance where targeting is valid
                if (mActorStances != null && mActorStances.Count > 0 && !mActorStances.Contains(mMotionController.Stance))
                {
                    IsTargetLocked = false;
                    OnTargetUnlocked(_Target);
                }

                // Finally, force the rotations as needed
                if (IsTargetLocked)
                {
                    if (_ForceActorRotation)
                    {
                        RotateActorToTarget(_Target, 360f);
                    }
                    if (_ForceCameraRotation && mMotionController.CameraRig == null)
                    {
                        RotateCameraToTarget(_Target, 360f);
                    }
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Called each frame that the action is active
        /// </summary>
        public override void Update()
        {
            if (!mIsShuttingDown)
            {
                bool lIsClicked = false;

                // Determine if we're done choosing a target
                if (mInputSource != null)
                {
                    // Check if we're cancelling
                    if (_CancelActionAlias.Length > 0 && mInputSource.IsJustPressed(_CancelActionAlias))
                    {
                        if (mSelectedTarget != null)
                        {
                            RemoveMaterial(mSelectedTarget.gameObject, mMaterialInstance);
                        }

                        mSelectedTarget = null;

                        if (OnCancelledEvent != null)
                        {
                            OnCancelledEvent(this, mSelectedTarget);
                        }

                        Stop();
                    }
                    // Check if we're selecting
                    else if (mInputSource.IsJustPressed(_ActionAlias))
                    {
                        lIsClicked = true;
                    }
                }

                // Determine if we should actively look for a target
                if (_ContinuousSelect || lIsClicked)
                {
                    bool lRayHit = Raycast(!_UseMouse);

                    if (lRayHit)
                    {
                        lRayHit = ValidateTarget();
                    }

                    if (!lRayHit)
                    {
                        if (mSelectedTarget != null)
                        {
                            RemoveMaterial(mSelectedTarget.gameObject, mMaterialInstance);
                        }

                        mSelectedTarget    = null;
                        transform.position = new Vector3(0f, (mOwner != null ? mOwner.transform.position.y : 0f) - 200f, 0f);
                    }
                }

                // Report the result of the target
                if (lIsClicked)
                {
                    if (mSelectedTarget != null)
                    {
                        RemoveMaterial(mSelectedTarget.gameObject, mMaterialInstance);
                    }

                    if (OnSelectedEvent != null)
                    {
                        OnSelectedEvent(this, mSelectedTarget);
                    }

                    Stop();
                }
            }

            // Handle the projectiles
            base.Update();
        }