private void checkAirStatsRefError() { if (air == null) { air = AirEnvironmentStats.getAir(); } }
public bool tryLock(CombatFlow targetFlow, bool debug = false) { if (lockableType(targetFlow) && !targetFlow.jamming) { heightDiffAdvantage = (transform.position.y - targetFlow.transform.position.y) * ALTITUDE_ADVANTAGE_FACTOR; closingSpeedAdv = calculateClosingSpeed(targetFlow.myRb) * closingSpeedFactor; yourSpeedAdv = myRb.velocity.magnitude * YOUR_SPEED_FACTOR; targetBearingLine = targetFlow.transform.position - transform.position; myPerpDragAdv = calculatePerpendicularVelocity(targetBearingLine, myRb.velocity) * myPerpendicularDragFactor; targetPerpDragAdv = calculatePerpendicularVelocity(targetBearingLine, targetFlow.myRb.velocity) * targetPerpendicularDragFactor; float velBearing = Vector3.Angle(targetFlow.myRb.velocity, transform.position - targetFlow.transform.position); // if target's velocity is facing away from player if (velBearing > 90f) { velBearing -= 90f; // how far past 90 degrees is velBearing velBearing /= 90f; // 1.0 is 90 degrees past perpendicular (straight away), 0.0 is perpendicular velBearing = Mathf.Lerp(1.0f, tgtFaceAwayPerpFactor, velBearing); velBearing = Mathf.Clamp(velBearing, 0.0f, 1.0f); // allows for 0.0 to be applied across some arc, by using negative tgtFaceAway val // I want: // 1.0 at 90 degrees // tgtFaceAwayPerpFactor at 180 targetPerpDragAdv *= velBearing; //Debug.LogWarning("==================== Target facing away. Cancelling perp factor down to: "+ targetPerpDragAdv + ", multiplier of: " + velBearing); } // average of three values, target alt twice to give more weight to the slow portion of flight avgAlt = (2 * targetFlow.transform.position.y + transform.position.y) / 3f; airDensityMod = AirEnvironmentStats.getAir().getDensityAtAltitude(avgAlt) * airDensityFactor; setRangeAdvantages(heightDiffAdvantage, closingSpeedAdv, yourSpeedAdv, myPerpDragAdv, targetPerpDragAdv, airDensityMod); angleOffNose = Vector3.Angle(targetFlow.transform.position - transform.position, transform.forward); dist = Vector3.Distance(targetFlow.transform.position, transform.position); if (rangeLadder != null && myFlow.isLocalPlayer) { rangeLadder.tgtRange = dist; } if (debug) { //Debug.Log("radarOn: " + radarOn + ", good lock angle: " + // (angleOffNose < lockAngle) + ", goodDist: " + (dist < maxLockRange)); //Debug.Log("angleOffNose: " + angleOffNose + ", lockAngle: " + lockAngle); } //return radarOn && angleOffNose < lockAngle && dist < (maxLockRange + heightDiffAdvantage + closingSpeedAdv) && tryDetect(targetFlow); return(radarOn && angleOffNose < lockAngle && dist < maxLockRange && tryDetect(targetFlow)); } else { if (debug) { Debug.Log("BadLockType, target is " + targetFlow.type + ", myRadar is : " + lockType); } setRangeAdvantages(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); return(false); } }