Beispiel #1
0
 protected virtual void Awake()
 {
     OnBecomesInactive();
     m_Shooting        = GetComponent <TankShooting>();
     m_Movement        = GetComponent <TankMovement>();
     m_FloorPlane      = new Plane(Vector3.up, 0);
     m_GroundLayerMask = LayerMask.GetMask("Ground");
 }
Beispiel #2
0
        private void Update()
        {
            if (!m_Initialized)
            {
                return;
            }

            if (!hasAuthority)
            {
                // Remote players interpolate their facing direction
                if (m_TurretTransform != null)
                {
                    m_ClientTurretHeading      = Mathf.SmoothDampAngle(m_ClientTurretHeading, m_TurretHeading, ref m_ClientTurretHeadingVel, m_LookDirInterpolate);
                    m_TurretTransform.rotation = Quaternion.AngleAxis(m_ClientTurretHeading, Vector3.up);
                }
                return;
            }

            if (s_localTank == null)
            {
                s_localTank = this;
            }

            // Reload time
            if (m_ReloadTime > 0)
            {
                m_ReloadTime -= Time.deltaTime;
            }

            //If the fire button has been released with the target point inside the tank's safety radius, we fire the hooter instead of continuing with fire logic.
            if (m_FireInput && !m_WasFireInput && InSafetyRange())
            {
                m_ShootingAudio.Stop();

                if (!m_HooterAudio.isPlaying)
                {
                    CmdFireMeep();
                }
            }
            // Otherwise, if the min angle has been exceeded and the shell hasn't yet been launched...
            else if (m_CurrentLaunchAngle <= m_MinLaunchAngle && !m_Fired)
            {
                // ... use the max force and launch the shell.
                m_CurrentLaunchAngle = m_MinLaunchAngle;
                Fire();
            }
            // Otherwise, if the fire button has just started being pressed...
            else if (m_FireInput && !m_WasFireInput && CanFire())
            {
                // ... reset the fired flag and reset the launch force.
                m_Fired = false;

                m_CurrentLaunchAngle = m_MaxLaunchAngle;

                // Change the clip to the charging clip and start it playing.
                m_ShootingAudio.clip = m_ChargingClip;
                m_ShootingAudio.Play();
            }
            // Otherwise, if the fire button is being held and the shell hasn't been launched yet...
            else if (m_FireInput && !m_Fired)
            {
                // Increment the launch force and update the slider.
                m_CurrentLaunchAngle -= m_ChargeSpeed * Time.deltaTime;
            }
            // Otherwise, if the fire button is released and the shell hasn't been launched yet...
            else if (!m_FireInput && m_WasFireInput && !m_Fired)
            {
                // ... launch the shell.
                Fire();
            }

            m_WasFireInput = m_FireInput;

            UpdateAimSlider();

            // Turret shake
            float   shakeMagnitude = Mathf.Lerp(0, m_ChargeShakeMagnitude, Mathf.InverseLerp(m_MaxLaunchAngle, m_MinLaunchAngle, m_CurrentLaunchAngle));
            Vector2 shakeOffset    = Vector2.zero;

            if (shakeMagnitude > 0)
            {
                shakeOffset.x = (Mathf.PerlinNoise((Time.realtimeSinceStartup + 0) * m_ChargeShakeNoiseScale, Time.smoothDeltaTime) * 2 - 1) * shakeMagnitude;
                shakeOffset.y = (Mathf.PerlinNoise((Time.realtimeSinceStartup + 100) * m_ChargeShakeNoiseScale, Time.smoothDeltaTime) * 2 - 1) * shakeMagnitude;
            }

            if (m_RecoilTime > 0)
            {
                m_RecoilTime = Mathf.Clamp01(m_RecoilTime - Time.deltaTime * m_FireRecoilSpeed);
                float recoilPoint = m_FireRecoilCurve.Evaluate(1 - m_RecoilTime);

                shakeOffset += m_RecoilDirection * recoilPoint * m_FireRecoilMagnitude;
            }

            m_TurretTransform.localPosition = m_DefaultTurretPos + new Vector3(shakeOffset.x, 0, shakeOffset.y);
        }