public override Steering Apply() { Steering st = new Steering(); if (IsFinished()) { callback(true); return(st); } if (defendZone.attack != null) { st = defendZone.Apply(); fighting = true; } else { defendZone.Apply(); //We don't want to return to the base but yes to keep checking for enemies if (fighting) { goTo.SetNewTarget(target); fighting = false; } st = goTo.Apply(); } //Attack any units that it sees in range defendZone.SetCenter(agent.position); return(st); }
public override Steering Apply() { if (IsFinished()) { callback(true); } Steering st = new Steering(); //Comprobar si se ha matado a la unidad if (attack == null || Util.HorizontalDist(targetEnemy.position, center) > rangeRadius + agent.militar.attackRange + followRangeExtra) { AgentUnit closerEnemy = Info.GetUnitsFactionArea(center, rangeRadius + agent.militar.attackRange, Util.OppositeFaction(agent.faction)) .OrderBy(enemy => Util.HorizontalDist(agent.position, enemy.position)) .FirstOrDefault(); AttackEnemy(closerEnemy); //if it does not find any target that it returns back to the center if (closerEnemy == null && !returning && Util.HorizontalDist(agent.position, center) > rangeRadius / 2) { goTo.SetNewTarget(center); goTo.SetVisiblePath(true); returning = true; } } if (attack != null) { st = attack.Apply(); } else if (returning) { st = goTo.Apply(); } return(st); }
/*Vector3 GetFutureTargetPosition() { * float lookAhead = Mathf.Clamp(Util.HorizontalDist(agent.position, target.position) / 2f, 0, 3); * Vector3 futurePosition = Map.Clamp(target.position + target.velocity * lookAhead); * //Only predict if it is not too close and the prediction is a walkable place * if (Util.HorizontalDist(agent.position, target.position) > 4f && Map.NodeFromPosition(futurePosition).isWalkable()) * return futurePosition; * else * return target.position; * }*/ public override Steering Apply() { Steering st = new Steering(); if (IsFinished()) { callback(true); return(st); } // If has reached range or fixed time reconsider path if (!inRange) { if (IsNearEnough()) { SetInRange(); } else if (Time.fixedTime - timeStamp > 2) { timeStamp = Time.fixedTime; ReconsiderPath(); } } //If the enemy it goes out of range else if (inRange && IsFarEnough()) { inRange = false; ReconsiderPath(); } if (!inRange) { st = goTo.Apply(); } return(st); }
public override Steering Apply() { Steering st = new Steering(); if (IsFinished()) { callback(true); return(st); } if (goTo != null) { st = goTo.Apply(); // Debug.Log("Aplicando goto"); } else if (defendZone != null) { st = defendZone.Apply(); } return(st); }