private void PickTargetToWatch() { //Debug.Log("to watch"); var knower = _followedTarget.TargetTransform.GetComponent("IKnowsCurrentTarget") as IKnowsCurrentTarget; if (knower != null && knower.CurrentTarget != null) { _targetToWatch = knower.CurrentTarget; //Debug.Log("Watching followed object's target: " + _targetToWatch.TargetTransform.name); } else { var targets = _detector.DetectTargets() .Where(t => t.TargetTransform.parent == null); //Don't watch anything that still has a parent. targets = _watchPicker.FilterTargets(targets) .OrderByDescending(s => s.Score); //foreach (var item in targets) //{ // Debug.Log(item.TargetTransform.name + ": " + item.Score); //} _targetToWatch = targets .FirstOrDefault(); //Debug.Log("Watching picked target: " + _targetToWatch.TargetTransform.name); } }
protected Vector3 VectorToCancelLateralVelocityInWorldSpace(PotentialTarget target) { var vectorTowardsTarget = ReletiveLocationInWorldSpace(target); var targetReletiveVelocity = WorldSpaceReletiveVelocityOfTarget(target); return(targetReletiveVelocity.ComponentPerpendicularTo(vectorTowardsTarget)); }
public override void Fly(PotentialTarget target) { RemoveNullEngines(); if (ShouldTurn() && HasStarted()) { var reletiveLocation = ReletiveLocationInWorldSpace(target); var cancelationVector = VectorToCancelLateralVelocityInWorldSpace(target); var targetReletiveVelocity = WorldSpaceReletiveVelocityOfTarget(target); var turningVector = (targetReletiveVelocity.magnitude * targetReletiveVelocity.magnitude * cancelationVector) + (reletiveLocation * LocationAimWeighting); //Debug.Log("Pilot angle: " + Vector3.Angle(turningVector, _pilotObject.transform.forward)); if (Vector3.Angle(turningVector, _pilotObject.transform.forward) > CloseEnoughAngle) { _torqueApplier.TurnToVectorInWorldSpace(turningVector); } //try firing the main engine even with no fuel to turn it off if there is no fuel. SetFlightVectorOnEngines(turningVector); if (VectorArrow != null && turningVector.magnitude > 0) { VectorArrow.rotation = Quaternion.LookRotation(turningVector); } } else { SetFlightVectorOnEngines(null); //turn off the engine } }
public void init(Unit _host, Collider _self, PotentialTarget _tgt = PotentialTarget.ANY, Decision _dec = Decision.IDEL) { ThinkTimer = new Utility.Timer(thinkPeriod); ThinkTimer.start_timer(); self = _self; unit = _host; _host.AI_unit = this; target = _tgt; decision = _dec; vision = GetComponent <CapsuleCollider> (); objWithin_Ally_champ = new List <GameObject>(); objWithin_Ally_minion = new List <GameObject>(); objWithin_Ally_struct = new List <GameObject>(); objWithin_Ally_item = new List <GameObject>(); objWithin_Hostile_champ = new List <GameObject>(); objWithin_Hostile_minion = new List <GameObject>(); objWithin_Hostile_struct = new List <GameObject>(); objWithin_Hostile_item = new List <GameObject>(); objWithin_neturals = new List <GameObject> (); listedby = new List <GameObject> (); temp_untargetable = new List <GameObject> (); init_special(); }
private void PickRandomToFollow() { _followedTarget = _detector .DetectTargets() .Where(s => s.TargetTransform.parent == null && s.TargetTransform != _followedTarget.TargetTransform) .OrderBy(s => UnityEngine.Random.value) .FirstOrDefault(); }
private PotentialTarget AddScoreForPrefered(PotentialTarget target) { target.IsValidForCurrentPicker = PreferdTypes.Contains(target.Type); if (target.IsValidForCurrentPicker) { target.Score += FlatBoost; } return(target); }
protected Vector3 WorldSpaceReletiveVelocityOfTarget(PotentialTarget target) { if (target == null) { return(Vector3.zero); } var targetsVelocity = target.TargetRigidbody == null ? Vector3.zero : target.TargetRigidbody.velocity; var ownVelocity = _pilotObject.velocity; return(targetsVelocity - ownVelocity); }
void UpdateList(bool add, PotentialTarget target) { if (add) { targets.Add(target); } else //take away { targets.Remove(target); } }
private PotentialTarget AddScoreForDifference(PotentialTarget target) { var dist = target.DistanceToTurret(_sourceObject); target.Score = target.Score - (dist * DistanceMultiplier); if (dist < Range) { target.Score += InRangeBonus; } return(target); }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player1(Black)" || other.tag == "Player2(White)" || other.tag == "Player3" || other.tag == "Player4") { PlayerHealth tempHealthScript = other.GetComponent <PlayerHealth>(); if (tempHealthScript.teamCount != teamCount) { PotentialTarget newTarget = new PotentialTarget(other.gameObject, false, tempHealthScript.teamCount); UpdateList(true, newTarget); } } }
private void DrawSingleLable(PotentialTarget target) { // Find the 2D position of the object using the main camera Vector3 boxPosition = Camera.main.WorldToScreenPoint(target.Transform.position); if (boxPosition.z > 0) { Vector3 baseLocation; if (_shipCam != null && _shipCam.FollowedTarget != null) { baseLocation = _shipCam.FollowedTarget.transform.position; } else { baseLocation = Camera.transform.position; } var distance = Vector3.Distance(baseLocation, target.Transform.position); // "Flip" it into screen coordinates boxPosition.y = Screen.height - boxPosition.y; if (target.Transform.parent == null) { //only draw for root objects (with no parents) GUI.Label(new Rect(boxPosition.x - 20, boxPosition.y - 35, 50, 20), target.Transform.tag); if (distance > MinShowDistanceDistance) { //Draw the distance from the followed object to this object - only if it's suitably distant. GUI.Label(new Rect(boxPosition.x - 20, boxPosition.y + 25, 40, 40), Math.Round(distance).ToString()); } } var rect = new Rect(boxPosition.x - 50, boxPosition.y - 50, 100, 100); DrawSingleReticle(target.Transform, rect); var healthControler = target.Transform.GetComponent <HealthControler>(); if (healthControler != null && healthControler.IsDamaged) { if (HealthBGTexture != null) { GUI.DrawTexture(rect, HealthBGTexture); } if (HealthFGTexture != null) { rect.width *= healthControler.HealthProportion; GUI.DrawTexture(rect, HealthFGTexture); } //Debug.Log(boxPosition.z + "--x--" + boxPosition.x + "----y--" + boxPosition.y); } } }
public bool CheckTarget(PotentialTarget target) { if (_handManager.GetSelectedCard() == null) { return(false); } if (!TargetingModeActive) { return(false); } // logic for whether target is valid will go here _target = target; return(true); }
private PotentialTarget AddScoreForAngle(PotentialTarget target) { var reletiveLocation = target.LocationInAimedSpace(_aimingObject, ProjectileSpeed); var distanceInFront = reletiveLocation.z; reletiveLocation.z = 0; var distanceToSide = reletiveLocation.magnitude; var angle = Math.Atan2(distanceToSide, distanceInFront); var newScore = Multiplier * (1 - (Math.Abs(angle) / Math.PI)); target.Score = target.Score + (float)newScore; return(target); }
private PotentialTarget AddScoreForDifference(PotentialTarget target) { var dist = target.DistanceToTurret(SourceObject); target.Score = target.Score - (dist * Multiplier); if (dist < Threshold) { target.IsValidForCurrentPicker = true; target.Score += FlatBoost; } else { target.IsValidForCurrentPicker = false; } return(target); }
private PotentialTarget AddScoreForAngle(PotentialTarget target) { var projectileSpeed = ProjectileSpeedKnower != null ? ProjectileSpeedKnower.KnownProjectileSpeed : 0; //TODO check this works. var reletiveLocation = AimingObject != null ? target.LocationInAimedSpace(AimingObject, projectileSpeed) : target.LocationInOthersSpace(AimingObjectFallback, projectileSpeed); var angle = Vector3.Angle(reletiveLocation, Vector3.forward); var newScore = Multiplier * (1 - (angle / 180)); newScore += angle < Threshold ? FlatBoost : 0; target.Score = target.Score + newScore; target.IsValidForCurrentPicker = angle < 90; return(target); }
protected Vector3 ReletiveLocationInWorldSpace(PotentialTarget target) { if (_pilotObject != null && target != null && target.TargetTransform.IsValid()) { var location = target.TargetTransform.position - _pilotObject.position; return(location); } //if (target == null || target.TargetTransform.IsInvalid()) //{ // Debug.Log("Target transform is invalid"); //} if (_pilotObject == null) { Debug.Log("_pilotObject is null"); } return(Vector3.zero); }
public void PlayCardIfValid() { Card card = _handManager.GetSelectedCard(); if (card != null) { PotentialTarget target = _targetManager.GetTarget(); if ( (card.GetTargetType() == TargetType.None) || (card.GetTargetType() == TargetType.Enemy && target != null && target.GetComponentInParent(typeof(Enemy)) != null) || (card.GetTargetType() == TargetType.Friendly && target != null && (target.GetComponentInParent(typeof(Carrier)) != null || target.GetComponentInParent(typeof(Fighter)) != null)) ) { PlayCard(card); } } }
private void PickBestTargetToFollow() { //Debug.Log("To Follow"); var targets = _detector.DetectTargets() .Where(t => t.TargetTransform.parent == null); //Don't follow anything that still has a parent. targets = _followPicker.FilterTargets(targets) .OrderByDescending(s => s.Score); //foreach (var item in targets) //{ // Debug.Log(item.TargetTransform.name + ": " + item.Score); //} _followedTarget = targets .FirstOrDefault(); if (_followedTarget != null) { _tagPicker.Tag = _followedTarget.TargetTransform.tag; } }
private void DrawSingleLable(PotentialTarget target) { // Find the 2D position of the object using the main camera Vector3 boxPosition = Camera.main.WorldToScreenPoint(target.TargetTransform.position); if (boxPosition.z > 0) { var distance = Vector3.Distance(transform.position, target.TargetTransform.position); // "Flip" it into screen coordinates boxPosition.y = Screen.height - boxPosition.y; //Draw the distance from the followed object to this object - only if it's suitably distant, and has no parent. if (distance > MinShowDistanceDistance && target.TargetTransform.parent == null) { GUI.Box(new Rect(boxPosition.x - 20, boxPosition.y + 25, 40, 40), Math.Round(distance).ToString()); } var rect = new Rect(boxPosition.x - 50, boxPosition.y - 50, 100, 100); if (ReticleTexture != null) { GUI.DrawTexture(rect, ReticleTexture); } var healthControler = target.TargetTransform.GetComponent("HealthControler") as HealthControler; if (healthControler != null && healthControler.IsDamaged) { if (HealthBGTexture != null) { GUI.DrawTexture(rect, HealthBGTexture); } if (HealthFGTexture != null) { rect.width *= healthControler.HealthProportion; GUI.DrawTexture(rect, HealthFGTexture); } //Debug.Log(boxPosition.z + "--x--" + boxPosition.x + "----y--" + boxPosition.y); } } }
private PotentialTarget AddScoreForDifference(PotentialTarget target) { Vector3 targetVelocity = target.TargetRigidbody == null ? Vector3.zero : target.TargetRigidbody.velocity; var relativeVelocity = _sourceObject.velocity - targetVelocity; var reletiveLocation = target.TargetTransform.position - _sourceObject.position; var approachAngle = Vector3.Angle(relativeVelocity, reletiveLocation); var angleComponent = (-approachAngle / 90) + 1; //now in range +-1 with positive being good. angleComponent = (float)Math.Pow(angleComponent, 3); //decrease influence near 90degrees var score = angleComponent * relativeVelocity.magnitude * _weighting; target.Score += score; //Debug.Log("angle = " + approachAngle + ", angleComponent = " + angleComponent + ", v=" + relativeVelocity.magnitude + ", extra score=" + score + ", total score =" + target.Score); return(target); }
// Update is called once per frame void Update() { if (_targetManager.TargetingModeActive) { PotentialTarget target = _targetManager.GetTarget(); Card card = _handManager.GetSelectedCard(); Vector3[] positions = new Vector3[2]; positions[0] = card.transform.position; positions[1] = GetCurrentMousePosition(); _lineRenderer.SetPositions(positions); if (target != null) { _lineRenderer.endColor = Color.green; } else { _lineRenderer.endColor = Color.red; } } }
/// <summary> /// <example> /// setting.Properties = new QuoteProperty[] { // QuoteProperty.LastTradePriceOnly, // QuoteProperty.ChangeInPercent, // QuoteProperty.OneyrTargetPrice, // QuoteProperty.PercentChangeFromFiftydayMovingAverage, // QuoteProperty.PercentChangeFromTwoHundreddayMovingAverage // }; /// </example> /// </summary> /// <param name="tickers"></param> /// <param name="quoteProperties"></param> /// <returns></returns> public async Task <PotentialTarget> GetFairValue(string ticker) { var data = new PotentialTarget(ticker); var tenYearsBondYield = DownloadHelper.GetQuote(new string[] { "^TNX" }, QuoteProperty.LastTradePriceOnly, QuoteProperty.ChangeInPercent); var currentPrice = DownloadHelper.GetQuote(new string[] { ticker }, QuoteProperty.LastTradePriceOnly, QuoteProperty.ChangeInPercent); var cpi = DownloadHelper.GetCpiData(); var earningForecast = GetNasdaqEarningForecast(ticker); await cpi; await tenYearsBondYield; await currentPrice; await earningForecast; data.CurrentMarketPrice = currentPrice.Result.Items[0].LastTradePriceOnly; var fairValue = FairValueEngine.DiscountedCurrentValue( earningForecast.Result.YearlyEarningForecasts[0].ConsensusEpsForecast, earningForecast.Result.Years, earningForecast.Result.YearlyEarningGrowth, cpi.Result, (double)tenYearsBondYield.Result.Items [0][QuoteProperty.LastTradePriceOnly]); data.FairValue = fairValue; return(data); }
public override void Fly(PotentialTarget target) { RemoveNullEngines(); if (ShouldTurn()) { var reletiveLocation = target == null ? -_pilotObject.position //Return to the centre if there is no target : ReletiveLocationInWorldSpace(target); var distance = reletiveLocation.magnitude; var isTooFar = distance > MaxRange; var isTooClose = distance < MinRange; var targetsVelosity = target == null ? -_pilotObject.velocity //if there's no target, go to stationary target at centre. : WorldSpaceReletiveVelocityOfTarget(target); var targetsTangentialVelocity = targetsVelosity.ComponentPerpendicularTo(reletiveLocation); var tanSpeed = targetsTangentialVelocity.magnitude; var targetsApproachVelocity = targetsVelosity.ComponentParalellTo(reletiveLocation); //var isApproaching = Vector3.Angle(targetsApproachVelocity, reletiveLocation) > 90; //var approachSpeed = isApproaching // ? targetsApproachVelocity.magnitude // : -targetsApproachVelocity.magnitude; var tangentialTooFast = tanSpeed > MaxTangentialSpeed; var tangentialTooSlow = tanSpeed < MinTangentialSpeed; var needsSlowdown = targetsApproachVelocity.magnitude > RadialSpeedThreshold; var happyWithSpeed = !tangentialTooFast && !tangentialTooSlow && targetsVelosity.magnitude < MaxTangentialSpeed && !needsSlowdown; var happyWithLocation = !isTooClose && !isTooFar; var completelyHappy = happyWithSpeed && happyWithLocation; var approachVector = CalculateWeightedApproachVector(reletiveLocation, isTooClose, isTooFar); var tanSpeedVector = CalculateWeightedTanSpeedVector(targetsTangentialVelocity, reletiveLocation, tangentialTooSlow, tangentialTooFast); var slowdownVector = CalculateWeightedSlowdownVector(targetsApproachVelocity, needsSlowdown); _slowdownMode = slowdownVector.magnitude > approachVector.magnitude; var turningVector = completelyHappy ? reletiveLocation : tanSpeedVector + (_slowdownMode ? slowdownVector : approachVector); //Debug.Log( // "slowdownMode: " + _slowdownMode + // ", distance: " + Math.Round(distance, 1) + // ", approachVector: " + approachVector + // ", tanSpeed: " + Math.Round(tanSpeed, 3) + // ", tanSpeedVector: " + tanSpeedVector + // ", VApproach: " + Math.Round(targetsApproachVelocity.magnitude, 3) + // ", slowdownVector: " + slowdownVector + // ", turningVector: " + turningVector); if (Vector3.Angle(turningVector, _pilotObject.transform.forward) > CloseEnoughAngle) { _torqueApplier.TurnToVectorInWorldSpace(turningVector); } if (VectorArrow != null) { if (!completelyHappy && turningVector.magnitude > 0) { VectorArrow.rotation = Quaternion.LookRotation(turningVector); VectorArrow.localScale = Vector3.one; } else { VectorArrow.localScale = Vector3.zero; } } if (completelyHappy) { SetFlightVectorOnEngines(null); } else { //try firing the main engine even with no fuel to turn it off if there is no fuel. SetFlightVectorOnEngines(turningVector); } } else { SetFlightVectorOnEngines(null); //turn off the engine } }
public void ClearTarget() { _target = null; }
private bool IsAllowed(PotentialTarget t) { return(!DisalowedTypes.Contains(t.Type)); }
public void set_target(PotentialTarget _tgt) { target = _tgt; }
public abstract void Fly(PotentialTarget target);