Exemple #1
0
        public virtual void UpdateInputs()
        {
            // Start by resetting our previous frame's inputs
            movementX = 0;
            movementY = 0;
            movementZ = 0;

            // Start with VR Controller Input
            Vector2 primaryAxis = GetMovementAxis();

            if (playerController && playerController.IsGrounded())
            {
                movementX = primaryAxis.x;
                movementZ = primaryAxis.y;
            }
            else if (AirControl)
            {
                movementX = primaryAxis.x * AirControlSpeed;
                movementZ = primaryAxis.y * AirControlSpeed;
            }

            // If VR Inputs not in use, check for keyboard inputs
            if (AllowKeyboardInputs && movementX == 0 && movementZ == 0)
            {
                GetKeyBoardInputs();
            }

            if (CheckJump())
            {
                movementY += JumpForce;
            }

            if (CheckSprint())
            {
                movementX *= StrafeSprintSpeed;
                movementZ *= SprintSpeed;
            }
            else
            {
                movementX *= StrafeSpeed;
                movementZ *= MovementSpeed;
            }
        }
        public virtual void MoveCharacter()
        {
            // Bail early if no elligible for movement
            if (UpdateMovement == false)
            {
                return;
            }

            Vector3 moveDirection = new Vector3(movementX, movementY, movementZ);

            if (ForwardDirection != null)
            {
                moveDirection = ForwardDirection.TransformDirection(moveDirection);
            }
            else
            {
                moveDirection = transform.TransformDirection(moveDirection);
            }

            // Check for jump value
            if (playerController != null && playerController.IsGrounded())
            {
                // Reset jump speed if grounded
                _verticalSpeed = 0;
                if (CheckJump())
                {
                    _verticalSpeed = JumpForce;
                }
            }

            moveDirection.y = _verticalSpeed;

            if (playerController)
            {
                playerController.LastPlayerMoveTime = Time.time;
            }

            if (moveDirection != Vector3.zero)
            {
                MoveCharacter(moveDirection * Time.deltaTime);
            }
        }
Exemple #3
0
        public virtual void ApplyGravityToPlayer()
        {
            if (playerController == null)
            {
                return;
            }

            // Apply gravity to Y
            if (ApplyGravity && !playerController.IsGrounded() && !playerController.GrippingClimbable && playerController.GravityEnabled)
            {
                playerController.LastPlayerMoveTime = Time.time;
                controller.Move(new Vector3(0, playerController.GravityAmount * -1, 0) * Time.deltaTime);
            }
        }