예제 #1
0
    private void GroundMove()
    {
        Vector3 wishDir;

        if (!_wishToJump)
        {
            _playerVelocity = PlayerMovementCalculations.CalculateFricition(_playerVelocity, _runDeacceleration, _groundFriction, _controller.isGrounded, 1);
        }
        else
        {
            _playerVelocity = PlayerMovementCalculations.CalculateFricition(_playerVelocity, _runDeacceleration, _groundFriction, _controller.isGrounded, 0);
        }

        SetMovementDirection();

        wishDir = new Vector3(_movementCommand.right, 0, _movementCommand.forward);
        wishDir = transform.TransformDirection(wishDir);
        wishDir.Normalize();

        var wishSpeed = wishDir.magnitude;

        wishSpeed *= _moveSpeed;

        _playerVelocity = PlayerMovementCalculations.CalculateAcceleration(_playerVelocity, wishDir, wishSpeed, _runAcceleration);

        _playerVelocity.y = -_gravity * Time.deltaTime;

        if (_wishToJump)
        {
            _playerVelocity.y = _jumpAcceleration;
            _wishToJump       = false;
        }
    }
예제 #2
0
        public void CalculateAcceleration()
        {
            var   playerVelocity = new Vector3(0f, -0.2f, 0.6f);
            var   wishDir        = new Vector3(0f, 0f, 1f);
            float wishSpeed      = 7f;
            float accel          = 14f;

            Vector3 result   = PlayerMovementCalculations.CalculateAcceleration(playerVelocity, wishDir, wishSpeed, accel);
            var     expected = new Vector3(0f, -0.2f, 7f);

            Assert.AreEqual(expected, result);
        }
예제 #3
0
        public void CalculateAirControl()
        {
            var   playerVelocity      = new Vector3(0f, -0.2f, 0.6f);
            var   wishDir             = new Vector3(0f, 0f, 1f);
            float airControlPrecision = 0.3f;
            float wishSpeed           = 7f;

            Vector3 result = PlayerMovementCalculations.CalculateAirControl(playerVelocity, wishDir, airControlPrecision, wishSpeed, 1f);

            var expected = new Vector3(0f, -0.2f, 0.6f);

            Assert.AreEqual(expected, result);
        }
예제 #4
0
        public void CalculateFriction_Air()
        {
            var   playerVelocity    = new Vector3(0f, -0.2f, 7f);
            float runDeacceleration = 10f;
            float groundFriction    = 6f;
            float baseFriction      = 1f;
            bool  isGrounded        = false;

            Vector3 result = PlayerMovementCalculations.CalculateFricition(
                playerVelocity,
                runDeacceleration,
                groundFriction,
                isGrounded,
                baseFriction
                );

            var expected = new Vector3(0f, -0.2f, 7f);

            Assert.AreEqual(expected, result);
        }
예제 #5
0
    private void AirMove()
    {
        Vector3 wishDir;
        float   accel;

        SetMovementDirection();

        wishDir = new Vector3(_movementCommand.right, 0, _movementCommand.forward);
        wishDir = transform.TransformDirection(wishDir);

        float wishSpeed = wishDir.magnitude;

        wishSpeed *= _moveSpeed;

        wishDir.Normalize();


        accel = Vector3.Dot(_playerVelocity, wishDir) < 0 ? _airDecceleration : _airAcceleration;

        if (_movementCommand.forward == 0 && _movementCommand.right != 0)
        {
            if (wishSpeed > _sideStrafeMaxSpeed)
            {
                wishSpeed = _sideStrafeMaxSpeed;
            }

            accel = _sideStrafeAcceleration;
        }

        _playerVelocity = PlayerMovementCalculations.CalculateAcceleration(_playerVelocity, wishDir, wishSpeed, accel);

        if (_airControlPrecision > 0)
        {
            _playerVelocity = PlayerMovementCalculations.CalculateAirControl(_playerVelocity, wishDir, _airControlPrecision, wishSpeed, _movementCommand.forward);
        }

        _playerVelocity.y -= _gravity * Time.deltaTime;
    }