private bool HasNewTarget(out FighterAgent targetAgent) { m_Sorted.Clear(); var pos = transform.position; var agents = m_AgentManager.AllAgents(); foreach (var agent in agents) { if (HasLineOfSight(agent)) { m_Sorted.Add(new SortableAgent { Agent = agent, Distance = (pos - agent.WorldPosition).magnitude }); } } m_Sorted.Sort(); foreach (var obj in m_Sorted) { if (HasOpponentInVicinity(obj.Agent)) { targetAgent = obj.Agent; return(true); } } // None found. targetAgent = m_TargetAgent; return(false); }
// Team rewards are supposed to encourage team work, like pack-hunting. // Although I havent't seen such behaviour emerging yet. protected void AddTeamReward(FighterAgent agent, bool opponents, float reward) { var team = TeamAgents(agent, opponents, m_Radius); foreach (var other in team) { other.AddReward(reward); } }
protected virtual void OnEpisodeBegin(FighterAgent agent) { agent.SetAgentActive(false); if (++m_AgentCount == m_NumAgents) { m_AgentCount = 0; OnEpisodeBegin(); } }
protected override void OnHealthDepleted(FighterAgent agent) { // Reward opponents in vicinity. AddTeamReward(agent, true, 1); // Penalize team members in vicinity. AddTeamReward(agent, false, -1f); // Back to default pos, episode continues. agent.ResetAgent(); }
protected override void Initialize() { m_AgentManager = FindObjectOfType <AgentManager>(); m_Sorted = new List <SortableAgent>(); m_TargetAgent = FindObjectOfType <FighterAgent>(); m_TargetPos = m_TargetAgent.transform.position; m_LookPos = m_TargetPos; InvokeRepeating("CheckState", 1, 1); }
public void OnBulletHitSuffered(FighterAgent agent) { var pos = cam.WorldToScreenPoint(agent.WorldPosition); if (pos.z > 0 && pos.z <= m_MaxDistance) { m_Opacity = 1; UpdatOpacity(); SetValue(agent.Health); StopAllCoroutines(); StartCoroutine(Dim(agent)); } }
public IEnumerable <FighterAgent> TeamAgents(FighterAgent centerAgent, bool opponents, float radius) { var team = m_Agents[opponents ? Tag.OpponentTag(centerAgent.tag) : centerAgent.tag]; var pos = centerAgent.WorldPosition; foreach (var other in team) { if (other != centerAgent && (other.WorldPosition - pos).magnitude <= radius) { yield return(other); } } }
private void TryTargetSwitch() { if (HasNewTarget(out FighterAgent targetAgent)) { m_TargetAgent = targetAgent; m_RepeatSelectCount = 0; } else { m_RepeatSelectCount++; } // Randomize anyway. m_Distance = Random.Range(m_DistanceRange.Min, m_DistanceRange.Max); m_Height = Random.Range(m_HeightRange.Min, m_HeightRange.Max); }
protected IEnumerator Dim(FighterAgent agent) { SetPosition(cam.WorldToScreenPoint(agent.WorldPosition)); float dt = Time.deltaTime; yield return(new WaitForSeconds(dt)); m_Opacity = Mathf.Max(0, m_Opacity - dt * m_DimSpeed); UpdatOpacity(); if (m_Opacity > 0) { StartCoroutine(Dim(agent)); } }
private bool HasLineOfSight(FighterAgent agent) { var delta = agent.WorldPosition - transform.position; return(!Physics.Raycast(transform.position, delta, delta.magnitude, Layer.ObstacleMask)); }
private bool HasOpponentInVicinity(FighterAgent agent) { var team = m_AgentManager.TeamAgents(agent, true, 10); return(team.ToArray().Length > 0); }
protected virtual void OnBulletHitScored(FighterAgent agent) { m_TeamHitsScoredCount[agent.tag]++; }
protected virtual void OnHealthDepleted(FighterAgent agent) { }