コード例 #1
0
 public override void OnStart()
 {
     //Get the agent, ball and team component
     agent  = GetComponent <SoccerAgent>();
     Ball   = agent.getBall().GetComponent <Ball>();
     isLeft = agent.WhichTeam();
 }
コード例 #2
0
ファイル: gizimo.cs プロジェクト: hanwangxxx/Soccer-AI-Game
        private void OnDrawGizmos()
        {
            agent  = GetComponent <SoccerAgent>();
            ball   = GameObject.FindGameObjectWithTag("ball");
            isLeft = agent.WhichTeam();

            Gizmos.color = Color.red;
            if (Condition.CanGoalKeeper(ball.transform.position, isLeft))
            {
                Gizmos.color = Color.green;
            }
            Gizmos.DrawLine(transform.position, ball.transform.position);


            // Gizmos.DrawWireSphere(transform.position, maxRadius);

            /*
             *          team.Sort((a, b) => {
             *              return Vector3.Distance(a.transform.position, ball.transform.position).CompareTo(Vector3.Distance(b.transform.position, ball.transform.position));
             *          });
             *
             *          Debug.Log(team[0]);
             *
             *          Gizmos.color = Color.red;
             *          if (team[0].transform.position == agent.transform.position) {
             *              Gizmos.color = Color.green;
             *          }
             *
             *          Gizmos.DrawLine(transform.position, ball.transform.position);
             *
             *      }*/
        }
コード例 #3
0
        /// <summary>
        /// Get agent position inside the defensive group;
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="targetPosition"></param>
        /// <param name="isLeft"></param>
        /// <returns></returns>
        public Vector3 GetDefenceGroupLocation(SoccerAgent agent, Vector3 targetPosition, bool isLeft)
        {
            //Get list of agent according the team;
            List <SoccerAgent> team = GetAgentTeam(isLeft);

            //Rank the distance between the player and the target point, the closest to the target point the top of the list;
            team.Sort((a, b) => {
                return(Vector3.Distance(a.transform.position, targetPosition).CompareTo(Vector3.Distance(b.transform.position, targetPosition)));
            });

            //Get agent index value after sorting;
            var index = team.FindIndex(a => a.getNum() == agent.getNum());

            // if the index value is 0, the target is the ball.
            if (index <= 0)
            {
                return(targetPosition);
            }
            else
            {
                //Align the agent to the nearest player who is closer to the ball
                var nearsMeAgentLocation = team[index - 1].transform.position;

                if (transform.position.z > nearsMeAgentLocation.z)
                {
                    return(new Vector3(nearsMeAgentLocation.x, 0, nearsMeAgentLocation.z + 3));
                }

                else
                {
                    return(new Vector3(nearsMeAgentLocation.x, 0, nearsMeAgentLocation.z - 3));
                }
            }
        }
コード例 #4
0
        public override void OnStart()
        {
            agent        = GetComponent <SoccerAgent>();
            ballLoaction = agent.getBall().transform;
            //Get the location of the Agent itself
            InitPos = agent.transform.position;
            //Set up patrol points
            PatrolPositions.Add(new Vector3(InitPos.x, InitPos.y, InitPos.z + Define.Patrol_Circle));
            PatrolPositions.Add(new Vector3(InitPos.x, InitPos.y, InitPos.z - Define.Patrol_Circle));
            //Choose a patrol point close to
            float distance = Mathf.Infinity;
            //Distance difference between agent and the patrol point
            float localDistance;

            for (int i = 0; i < PatrolPositions.Count; ++i)
            {
                if ((localDistance = Vector3.Magnitude(agent.transform.position - PatrolPositions[i])) < distance)
                {
                    distance = localDistance;
                    index    = i;
                }
            }
            PatrolPos = PatrolPositions[index];
            agent.setDestination(PatrolPos);
        }
コード例 #5
0
 public override void OnStart()
 {
     mAgent       = GetComponent <SoccerAgent>();
     isLeft       = mAgent.WhichTeam();
     ballLoaction = mAgent.getBallPosition();
     ball         = mAgent.getBall().GetComponent <Ball>();
 }
コード例 #6
0
 public override void OnStart()
 {
     Ball      = Agent.getBall().GetComponent <Ball>();
     isLeft    = Agent.WhichTeam();
     Agent     = GetComponent <SoccerAgent>();
     originPos = Agent.transform.position;
 }
コード例 #7
0
        /// <summary>
        /// Get the position in the attacker team;;
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="targetPosition"></param>
        /// <param name="isLeft"></param>
        /// <returns></returns>
        public Vector3 GetAttackGroupLocation(SoccerAgent agent, Vector3 targetPosition, bool isLeft)
        {
            //Get a list of players according to the team
            List <SoccerAgent> team = GetAgentTeam(isLeft);

            //Rank the distance between the player and the target point, with the closest to the target point will be set at the top of the list;
            team.Sort((a, b) => {
                return(Vector3.Distance(a.transform.position, targetPosition).CompareTo(Vector3.Distance(b.transform.position, targetPosition)));
            });

            //Get the index value after sorting;
            var index = team.FindIndex(a => a.getNum() == agent.getNum());

            // Index value of 0 is the closest player to the target point;
            if (index == 0)
            {
                return(targetPosition);
            }
            else
            {
                // Get the position of the closest player to the target point;
                var nearstBallAgentLocation = team[0].transform.position;
                int position = (index + 1) / 2;

                if ((index % 2) == 0)
                {
                    //If the index is even, place it on the side of the player closest to the target point;
                    return(new Vector3(nearstBallAgentLocation.x, 0, nearstBallAgentLocation.z - position * 6));
                }
                //If the index is an odd number, place the side of the player nearest to the target point, above the pitch;
                return(new Vector3(nearstBallAgentLocation.x, 0, nearstBallAgentLocation.z + position * 6));
            }
        }
コード例 #8
0
 public override TaskStatus OnUpdate()
 {
     nearPlayer = AttackStrategy.Instance.findNear(mAgent, isLeft);
     if (nearPlayer.getNum() == mAgent.getNum())
     {   //if we are the closest player to the goal return failure
         return(TaskStatus.Failure);
     }
     else
     {
         // if we are not the clost player to the goal.
         if (Condition.CanKickBall(mAgent.transform.position, ballLoaction))
         {
             mAgent.transform.LookAt(ballLoaction);
             //shoot the ball to the nearest attacker
             ball.AddForce(ballLoaction, nearPlayer.transform.position);
             return(TaskStatus.Success);
         }
         return(TaskStatus.Failure);
     }
 }
コード例 #9
0
        //Find the player closest to the goal to the pass ball
        public SoccerAgent findNear(SoccerAgent agent, bool isLeft)
        {
            List <SoccerAgent> team = GetAgentTeam(isLeft);

            if (isLeft)
            {
                team.Sort((a, b) =>
                {
                    return(Vector3.Distance(a.transform.position, Define.RightDoorPosition).CompareTo(Vector3.Distance(b.transform.position, Define.RightDoorPosition)));
                });
            }
            else
            {
                team.Sort((a, b) =>
                {
                    return(Vector3.Distance(a.transform.position, Define.LeftDoorPosition).CompareTo(Vector3.Distance(b.transform.position, Define.LeftDoorPosition)));
                });
            }

            return(team[0]);
        }
コード例 #10
0
 public override void OnStart()
 {
     Agent  = GetComponent <SoccerAgent>();
     Ball   = Agent.getBall().GetComponent <Ball>();
     isLeft = Agent.WhichTeam();
 }
コード例 #11
0
 public override void OnStart()
 {
     //Get agent Scripts
     Agent  = GetComponent <SoccerAgent>();
     isLeft = Agent.WhichTeam();
 }
コード例 #12
0
 void Start()
 {
     agent  = GetComponent <SoccerAgent>();
     Ball   = agent.getBall().GetComponent <Ball>();
     isLeft = agent.WhichTeam();
 }