Exemplo n.º 1
0
    // Aplikuje na bosse gravitační sílu
    private void ApplyGravity()
    {
        if (_grounded)
        {
            _timeSinceGrounded = 0;
        }
        else
        {
            _timeSinceGrounded += Time.fixedDeltaTime;
        }

        float gravitationalForce = GamePhysics.GetGravitationalForce(_timeSinceGrounded);

        transform.position = new Vector3(transform.position.x, transform.position.y + gravitationalForce, transform.position.z);
    }
Exemplo n.º 2
0
    // Spočítá novou pozici postavy; bere v potaz stav postavy a vstup hráče
    private void CalculatePosition()
    {
        // Když je postava na zemi, nastaví časovač stráveného času ve vzduchu na 0
        if (_grounded)
        {
            if (_jumping)
            {
                // Po stisknutí tlačítka ke skoku nechá postavu se "odrazit" od země
                if (_jumpNow == false)
                {
                    _jumping        = false;
                    _canDoAction    = true;
                    _acceptingInput = true;
                }
            }
            _timeSinceGrounded = 0;
        }
        else   // Jinak přičte k času strávenému ve vzduchu, čas strávený ve vzduchu před opětovným zavoláním této metody
        {
            _timeSinceGrounded += Time.fixedDeltaTime;
        }

        // Když hráč vyskočil do vzduchu je u výpočtu gravitace brán ohled na původní rychlost
        if (_jumping)
        {
            _currentGravity = GamePhysics.GetGravitationalForceWithInitialVelocity(_timeSinceGrounded, _jumpForce);
        }
        else   // Jinak pouze počítá gravitační sílu
        {
            _currentGravity = GamePhysics.GetGravitationalForce(_timeSinceGrounded);
        }

        // Když postava útočí, tak na ni působí pouze gravitace
        if (_attacking)
        {
            _velocity = new Vector3(0, _currentGravity, 0);
        }
        else if (_rolling) // Postava vykonává kotoul stále stejným směrem
        {
            _velocity   = _rollVector;
            _velocity.y = _currentGravity;
            if (_rollTimer < _rollDuration)
            {
                _rollTimer += Time.fixedDeltaTime;
            }
            else
            {
                _rolling        = false;
                _canDoAction    = true;
                _acceptingInput = true;
            }
        }
        else // Když pohyb postavy není omezen, pak je se pohybuje podle vstupu hráče
        {
            _velocity   = new Vector3(_joystickInput.x, 0, _joystickInput.z) * _moveSpeed;
            _velocity.y = _currentGravity;
            _velocity   = Quaternion.Euler(0, _yCameraRotation, 0) * _velocity;

            if (!_jumping)
            {
                // Nastaví animaci postavy podle toho, jestli se pohybuje
                if (_joystickInput.x == 0 && _joystickInput.z == 0)
                {
                    animator.SetBool("Run", false);
                }
                else
                {
                    animator.SetBool("Run", true);
                }
            }
        }

        transform.position += _velocity;
    }
Exemplo n.º 3
0
    // Počítá sílu gravitace
    private void CalculateYSpeed()
    {
        if (_grounded)
        {
            _timeSinceGrounded = 0;
        }
        else
        {
            _timeSinceGrounded += Time.fixedDeltaTime;
        }

        transform.position = new Vector3(transform.position.x, transform.position.y + GamePhysics.GetGravitationalForce(_timeSinceGrounded), transform.position.z);
    }