Beispiel #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;
        }
    }
Beispiel #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);
        }
Beispiel #3
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;
    }