Esempio n. 1
0
 private void RicochetChecking()
 {
     if (_ship.position.x > _field.xMax || _ship.position.x < _field.xMin)
     {
         _direction.Scale(HorizontalMirror);
         _flyDirection.Scale(HorizontalMirror);
         _ricochet.Start();
     }
     if (_ship.position.y > _field.yMax || _ship.position.y < _field.yMin)
     {
         _direction.Scale(VerticalMirror);
         _flyDirection.Scale(VerticalMirror);
         _ricochet.Start();
     }
 }
Esempio n. 2
0
    private void ShipMovement()
    {
        var mousePos = _camera.ScreenToFrustumPoint(Input.mousePosition);

        _course = (mousePos - _ship.position).normalized;

        if (Input.GetMouseButton(0))
        {
            _acceleration.Start();
        }
        else
        {
            _acceleration.Stop();
        }

        if (_acceleration)
        {
            _direction = Vector3.RotateTowards(_direction, _course, _rotateSpeed * Time.deltaTime, 0f);
        }

        var seedMod = _acceleration || _ricochet ? _accelerationMod : 1f;

        _flyDirection += _direction * _speed * seedMod * Time.deltaTime;
        if (_flyDirection.magnitude > _speed * seedMod)
        {
            _flyDirection -= _flyDirection.normalized * _speed * _accelerationMod * Time.deltaTime;
        }

        _ship.rotation  = Quaternion.LookRotation(_direction, Vector3.forward);
        _ship.position += (Vector3)(_flyDirection * Time.deltaTime);
    }