Example #1
0
    protected override void OnUpdate()
    {
        Vector3 pos   = transform.localPosition;
        float   dx    = Input.GetAxis("Horizontal");
        float   dy    = Input.GetAxis("Vertical");
        Vector3 delta = new Vector3(dx, dy);

        bool didPressDash = ButtonManager.Instance.GetButtonDown(ButtonManager.DashButton);

        _dashTimer -= Time.deltaTime;
        if (didPressDash && _mana.CanSpend(_dashManaCost))
        {
            _mana.Spend(_dashManaCost);
            _dashTimer = _dashDuration;
            _health.SetInvincibleFor(_dashInvincibilityDuration);
        }
        if (_dashTimer > 0.0f)
        {
            float t     = _dashTimer / _dashDuration;
            float speed = t * _moveSpeed + (1.0f - t) * _dashSpeed;
            _vel = delta * speed;

            // t*(t - 1)*(t - 1) = t^3 - 2t^2 + t
            // cubic w/ zeros at 0 and 1
            // also needs to be multiplied by ~7 to have a range near [0,1]
            float t2 = 1.0f - t;
            float s  = 7.0f * t2 * (1 + t2 * (-2 + t2));
            pos.z = _origin.z + s * _dashForwardDistance;
            transform.localPosition = pos;
        }
        else
        {
            float t = Time.deltaTime / _moveAccelTime;
            float s = 1.0f - t;
            _vel = _vel * s + t * delta * _moveSpeed;
        }

        Vector3 moveLook = new Vector3(_vel.x, _vel.y, _lookAheadDist);

        transform.LookAt(transform.position + moveLook);
    }
Example #2
0
 private bool canShoot()
 {
     return(_mana.CanSpend(_manaCost) && Time.time >= _cooledDownTime);
 }