void Update() { if(HighLogic.LoadedSceneIsFlight && FlightGlobals.ready && !vessel.packed && vessel.IsControllable) { if(lowpassFilter) { if(InternalCamera.Instance && InternalCamera.Instance.isActive) { lowpassFilter.enabled = true; } else { lowpassFilter.enabled = false; } } if(weaponState == WeaponStates.Enabled && (TimeWarp.WarpMode != TimeWarp.Modes.HIGH || TimeWarp.CurrentRate == 1)) { userFiring = (BDInputUtils.GetKey(BDInputSettingsFields.WEAP_FIRE_KEY) && (vessel.isActiveVessel || BDArmorySettings.REMOTE_SHOOTING) && !MapView.MapIsEnabled && !aiControlled); if((userFiring || autoFire) && (yawRange == 0 || (maxPitch-minPitch) == 0 || turret.TargetInRange(finalAimTarget, 10, float.MaxValue))) { if(eWeaponType == WeaponTypes.Ballistic || eWeaponType == WeaponTypes.Cannon) { finalFire = true; //Fire(); } } else { if(spinDownAnimation) spinningDown = true; if(eWeaponType == WeaponTypes.Laser) audioSource.Stop(); if(!oneShotSound && wasFiring) { audioSource.Stop(); wasFiring = false; audioSource2.PlayOneShot(overheatSound); } } } else { audioSource.Stop (); autoFire = false; } if(spinningDown && spinDownAnimation && hasFireAnimation) { if(fireState.normalizedTime>1) fireState.normalizedTime = 0; fireState.speed = fireAnimSpeed; fireAnimSpeed = Mathf.Lerp(fireAnimSpeed, 0, 0.04f); } } }
void SlavedAim() { Vector3 targetPosition; Vector3 targetVel; Vector3 targetAccel; if (weaponManager.slavingTurrets) { targetPosition = weaponManager.slavedPosition; targetVel = weaponManager.slavedVelocity; targetAccel = weaponManager.slavedAcceleration; //targetPosition -= vessel.srf_velocity * predictedFlightTime; } else if (legacyGuardTarget) { targetPosition = legacyGuardTarget.CoM; targetVel = legacyGuardTarget.srf_velocity; targetAccel = legacyGuardTarget.acceleration; } else { targetInTurretView = false; return; } currentTgtRange = Vector3.Distance(targetPosition, rockets[0].parent.transform.position); targetPosition += trajectoryOffset; targetPosition += targetVel * predictedFlightTime; targetPosition += 0.5f * targetAccel * predictedFlightTime * predictedFlightTime; turret.AimToTarget(targetPosition); targetInTurretView = turret.TargetInRange(targetPosition, 2, maxTargetingRange); }