예제 #1
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);
        }
예제 #2
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;
    }