private void Retaliate() { Helper.ClosestResult target = GameManager.Instance.Enemies.ClosestTo(transform.position, sqrAttackRadius); if (target.Character != null) { Attack(target.Character); } }
private void Pursue(Helper.ClosestResult target) { Vector3 targetPos = target.Character.transform.position; float t = Mathf.Sqrt(target.SqrDistance) / target.Character.Motor.maxSpeed; targetPos += t * target.Character.Motor.Rigidbody.velocity; Vector3 move = Motor.Arrive(targetPos).desiredVelocity; move += Separation(GameManager.Instance.EnemyGameObjects); move += Cohesion(GameManager.Instance.EnemyGameObjects); Motor.Move(move); }
protected override void FixedUpdate() { Helper.ClosestResult target = GameManager.Instance.Followers.Concat(new[] { GameManager.Instance.Player }) .ClosestTo(transform.position, sqrPursueSearchDistance); if (target.Character == null) { WanderGrouped(); } else if (target.SqrDistance <= sqrAttackRadius) { Attack(target.Character); } else { Pursue(target); } }