Exemple #1
0
    public IEnumerator AutomatedShoot()
    {
        ShipClass target = null;
        Rigidbody rb     = null;

        if (shipClass.Fleet.Enemies.Count < 1)
        {
            useTargettingSystem = false;
            yield break;
        }

        int random = Random.Range(0, shipClass.Fleet.Enemies.Count - 1);

        if (shipClass.Fleet != null)
        {
            target = shipClass.Fleet.Enemies[random];
            rb     = target.GetComponent <Rigidbody>();
        }

        while (target != null && transform != null && target.Alive && shipClass.Alive)
        {
            float   distance = Vector3.Distance(transform.position, target.transform.position);
            float   time     = distance / 600f;
            Vector3 lead     = rb.velocity * time;

            weapons.Target(target.transform.position + lead);
            weapons.Fire(target.transform.position + lead);
            yield return(new WaitForSeconds(0.025f));
        }

        StartCoroutine(AutomatedShoot());
        yield return(null);
    }
Exemple #2
0
    private void MouseInput()
    {
        if (weapons == null)
        {
            return;
        }

        Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        Vector3    point;

        if (Physics.Raycast(ray, out hit, 20000F))
        {
            point      = hit.point;
            lastKnownZ = hit.point.z;
        }
        else
        {
            Vector3 screen = Input.mousePosition;
            screen.z = lastKnownZ;
            point    = camera.ScreenToWorldPoint(screen);
            //Debug.DrawLine(camera.transform.position, point, Color.red, 5f);
        }

        weapons.Target(point);

        if (Input.GetMouseButtonDown(1))
        {
            weapons.Fire(point);
        }
    }
Exemple #3
0
 private void Fire()
 {
     if (_wpController == null)
     {
         return;
     }
     if (_nextShoot >= _statsController.GetCurrentFireRate())
     {
         _wpController.Fire();
         _nextShoot = 0;
     }
 }
Exemple #4
0
        private void Update()
        {
            if (!Alive)
            {
                return;
            }

            if (EngineRunning)
            {
                // Simple and temporary engine pitch adjustment code based on rigidbody velocity - should be using wheels.
                const float firstGearTopSpeed   = 40f;
                const float gearRatioAdjustment = 1.5f;
                const float minPitch            = 0.6f;
                const float maxPitch            = 1.2f;

                float velocity     = _rigidBody.velocity.magnitude;
                float gearMaxSpeed = firstGearTopSpeed;
                while (velocity / gearMaxSpeed > maxPitch - minPitch)
                {
                    gearMaxSpeed *= gearRatioAdjustment;
                }

                float enginePitch = minPitch + velocity / gearMaxSpeed;
                _engineLoopSound.pitch = enginePitch;
            }

            if (_engineStarting)
            {
                _engineStartTimer += Time.deltaTime;
                if (_engineStartTimer > _engineStartSound.clip.length - 0.5f)
                {
                    _engineLoopSound.Play();
                    EngineRunning     = true;
                    _engineStarting   = false;
                    _engineStartTimer = 0f;
                }
            }

            Movement.Update();

            if (_camera.FirstPerson)
            {
                if (_compassPanel != null)
                {
                    _compassPanel.UpdateCompassHeading(_transform.eulerAngles.y);
                }
            }

            // Always process radar panel, even outside first person view.
            if (RadarPanel != null)
            {
                RadarPanel.Update();
            }

            if (!IsPlayer || !CameraManager.Instance.IsMainCameraActive)
            {
                AI.Navigate();
            }

            if (!IsPlayer && FireWeapons)
            {
                if (WeaponsController != null)
                {
                    WeaponsController.Fire(0);
                }
            }
        }