// Update is called once per frame
    void Update()
    {
        if (_ship == null)
        {
            return;
        }

        Ray   mouseRay  = _camera.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y));
        Plane playPlane = new Plane(Vector3.up, _ship.GetControlled().transform.position);
        float distance  = 0f;

        if (playPlane.Raycast(mouseRay, out distance))
        {
            // TODO: This is very hacky
            Rigidbody rb         = _ship.GetControlled().GetComponent <Rigidbody>();
            BasicShip ship       = _ship.GetControlled().GetComponent <BasicShip>();
            Vector3   mousePos   = mouseRay.origin + mouseRay.direction * distance;
            Vector3   toMousePos = mousePos - _ship.GetControlled().transform.position;
            toMousePos.Normalize();
            float angleBetween = Vector3.Angle(toMousePos, _ship.GetControlled().transform.forward);
            float timeToMouse  = angleBetween / (Mathf.Abs(rb.angularVelocity.y * Mathf.Rad2Deg));
            //Debug.Log(timeToMouse + " " + Mathf.Abs(rb.angularVelocity.y * Mathf.Rad2Deg) / ship.Engine.TurnAcceleration);
            //Debug.Log(Mathf.Abs(rb.angularVelocity.y * Mathf.Rad2Deg) / ship.Engine.TurnAcceleration);
            float direction = Vector3.Dot(toMousePos, _ship.GetControlled().transform.right);
            //if(timeToMouse <= Mathf.Abs(rb.angularVelocity.y * Mathf.Rad2Deg) / ship.Engine.TurnAcceleration)
            //{
            //    _ship.Turn(-Mathf.Sign(direction));
            //}
            if (Mathf.Abs(rb.angularVelocity.y * Mathf.Rad2Deg) * Time.fixedDeltaTime >= angleBetween)
            {
                ship.GetControlled().transform.LookAt(mousePos);
                rb.angularVelocity = Vector3.zero;
            }
            else
            {
                _ship.Turn(Mathf.Sign(direction));
            }
        }


        _ship.Thrust(Input.GetAxis("Vertical"));
        _ship.LateralThrust(Input.GetAxis("Horizontal"));
        if (Input.GetButtonDown("PrimaryFire"))
        {
            _ship.MainWeaponTriggerDown();
        }
        else if (Input.GetButtonUp("PrimaryFire"))
        {
            _ship.MainWeaponTriggerUp();
        }
        if (Input.GetButtonDown("SecondaryFire"))
        {
            _ship.SecondaryWeaponTriggerDown();
        }
        else if (Input.GetButtonUp("SecondaryFire"))
        {
            _ship.SecondaryWeaponTriggerUp();
        }
        if (Input.GetButtonDown("FullStop"))
        {
            _ship.FullStopDown();
        }
        if (Input.GetButtonUp("FullStop"))
        {
            _ship.FullStopUp();
        }
        if (Input.GetButtonDown("Warp"))
        {
            _ship.EngageWarp();
        }
        else if (Input.GetButtonUp("Warp"))
        {
            _ship.DisengageWarp();
        }
    }
 public ShipModule_TimedSwitch(float duration, Button button, BasicShip ship, List <IEffect> effects) : base(button, ship)
 {
     this.duration = duration;
     this.effects  = effects;
 }
 public ShipModule_Beam(LineRenderer beam, float baseDamage, Button button, BasicShip ship) : base(button, ship)
 {
     this.qBeam = beam;
     damage     = new float_field(baseDamage);
 }
 public ShipModule_Projectile(GameObject bulletPrefab, float baseSpeed, float baseRange, float baseDamage, float baseSpread, int bulletsPerShot, float baseFiringRate, bool automatic, Button button, BasicShip ship) : base(button, ship)
 {
     this.bulletPrefab   = bulletPrefab;
     this.speed          = new float_field(baseSpeed);
     this.range          = new float_field(baseRange);
     this.damage         = new float_field(baseDamage);
     this.spread         = new float_field(baseSpread);
     this.bulletsPerShot = new int_field(bulletsPerShot);
     this.firingRate     = new float_field(baseFiringRate);
     this.automatic      = new bool_field(automatic);
 }
 public ShipModule(Button button, BasicShip ship)
 {
     this.button = button;
     this.ship   = ship;
 }