Example #1
0
        private void Update()
        {
            movementZ = InputSplitter.GetVerticalAxis(PlayerID);
            movementX = InputSplitter.GetHorizontalAxis(PlayerID);
            if (InputSplitter.GetSlidePressed(PlayerID))
            {
                shouldSlide = true;
            }

            if (InputSplitter.GetJumpPressed(PlayerID))
            {
                shouldJump = true;
            }
        }
Example #2
0
        private void UpdateSlideMotion()
        {
            float   movementZ  = 1.0f;
            float   movementX  = InputSplitter.GetHorizontalAxis(PlayerID);
            Vector3 moveVector = new Vector3(movementX, 0, movementZ);

            if (moveVector != Vector3.zero)
            {
                float moveMagnitude = moveVector.magnitude;
                moveVector   /= moveMagnitude;
                moveMagnitude = Mathf.Min(1.0f, moveMagnitude);

                moveVector = (transform.rotation * moveVector) * RunSpeed * moveMagnitude;
            }

            velocity.x = moveVector.x;
            velocity.z = moveVector.z;

            // Apply Gravity
            velocity.y -= 9.81f * Time.fixedDeltaTime;

            // Actually move
            // TODO: Check new velocity after update, we might need to exit slide (e.g if we slide into a wall)
            MoveAndUpdateVelocity();

            if (charController.isGrounded)
            {
                velocity.y = 0.0f;
            }

            // Apply sliding slowdown
            RunSpeed -= SlideDeceleration * Time.fixedDeltaTime;

            // We should stop sliding if we are either:
            //  1) No longer moving fast enough to warrant a slide
            //  2) No longer holding down the slide key
            bool shouldStopSlide = false;

            shouldStopSlide = shouldStopSlide || (RunSpeed < SlideStopSpeedThreshold);
            shouldStopSlide = shouldStopSlide || (!InputSplitter.GetSlide(PlayerID));
            if (shouldStopSlide)
            {
                headBob.enabled = true;

                currentMotion = DefinedMotion.NONE;
                SetAnimBool(animParamSlide, false);
                RunSpeed = DefaultRunSpeed;
            }
        }