예제 #1
0
 public override TaskStatus OnUpdate()
 {
     //Get the position of the ball;
     ballLocation = agent.getBallPosition();
     //Get the position of itself;
     agentLocation = agent.transform.position;
     //If the football is within kickable range;
     if (Condition.CanKickBall(agentLocation, ballLocation))
     {
         //Towards the ball;
         agent.transform.LookAt(ballLocation);
         //Depending on the team, give the ball a force;
         if (isLeft)
         {
             Ball.AddForce(ballLocation, Define.RightDoorPosition);
         }
         else
         {
             Ball.AddForce(ballLocation, Define.LeftDoorPosition);
         }
         //return success;
         return(TaskStatus.Success);
     }
     else
     {
         //Get agent position inside the attacking formation;
         targetLocation = AttackStrategy.Instance.GetAttackGroupLocation(agent, ballLocation, isLeft);
         //Set the target points;
         agent.setDestination(targetLocation);
         //return running;
         return(TaskStatus.Running);
     }
 }
예제 #2
0
 public override void OnStart()
 {
     mAgent       = GetComponent <SoccerAgent>();
     isLeft       = mAgent.WhichTeam();
     ballLoaction = mAgent.getBallPosition();
     ball         = mAgent.getBall().GetComponent <Ball>();
 }
예제 #3
0
        public override TaskStatus OnUpdate()
        {
            //Get the position of the football
            ballLoaction = Agent.getBallPosition();
            //Get the agent's position
            agentLoaction = Agent.transform.position;
            //Determines if the football has entered the goalkeeper's area, if it has, returns Success
            if (Condition.CanGoalKeeper(ballLoaction, isLeft))
            {   //Can goalkeeper kick the ball
                if (Condition.CanKickBall(agentLoaction, ballLoaction))
                {
                    Agent.transform.LookAt(ballLoaction);
                    //Give a force with direction according to the team
                    bool bLeft = Agent.WhichTeam();
                    if (bLeft)
                    {
                        Ball.AddForceBig(ballLoaction, Define.RightDoorPosition);
                        Agent.setDestination(originPos);
                    }
                    else
                    {
                        Ball.AddForceBig(ballLoaction, Define.LeftDoorPosition);
                        Agent.setDestination(originPos);
                    }
                    return(TaskStatus.Success);
                }
                else
                {
                    Agent.setDestination(ballLoaction);
                    return(TaskStatus.Running);
                }
            }

            return(TaskStatus.Failure);
        }
예제 #4
0
 public override TaskStatus OnUpdate()
 {
     //Get football position;
     ballLocation = Agent.getBallPosition();
     //Get agent position;
     agentLocation = Agent.transform.position;
     //To get into this node the agent must have seen the ball
     if (Condition.CanKickDefence(agentLocation, ballLocation))
     {
         //if close to the ball
         if (Condition.CanKickBall(agentLocation, ballLocation))
         {
             //face to the ball ;
             Agent.transform.LookAt(ballLocation);
             //Depending on the direction of opponent's goal, give the ball a force;
             bool isLeft = Agent.WhichTeam();
             if (isLeft)
             {
                 Ball.AddForceBig(ballLocation, Define.RightDoorPosition);
             }
             else
             {
                 Ball.AddForceBig(ballLocation, Define.LeftDoorPosition);
             }
             //Return successful;
             return(TaskStatus.Success);
         }
         else
         {
             if (Condition.CanDefenceGroup(Agent.WhichTeam(), Agent.transform.position, ballLocation))
             {
                 var target = DefenceStrategy.Instance.GetDefenceGroupLocation(Agent, ballLocation, isLeft);
                 Agent.setDestination(target);
                 return(TaskStatus.Running);
             }
             else
             {
                 //agent can defence the ball, but the distance is not enought to kick the ball, so move towards the ball;
                 Agent.setDestination(ballLocation);
             }
             return(TaskStatus.Running);
         }
     }
     // return Failure when can't defence the ball;
     return(TaskStatus.Failure);
 }
예제 #5
0
 void Kickball()
 {
     ballLocation  = agent.getBallPosition();
     agentLocation = agent.transform.position;
     if (Condition.CanKickBall(agentLocation, ballLocation))
     {
         //Depending on the team, give the ball a force;
         if (isLeft)
         {
             Ball.AddForce(ballLocation, Define.RightDoorPosition);
         }
         else
         {
             Ball.AddForce(ballLocation, Define.LeftDoorPosition);
         }
     }
 }
예제 #6
0
 public override TaskStatus OnUpdate()
 {
     ballLoaction = Agent.getBallPosition();
     //Determining whether the ball is in the keeper's zone
     if (Condition.CanGoalKeeper(ballLoaction, isLeft))
     {
         //If it is in goal keeper field, give the goalkeeper a reinforcement on speed and accelaeration
         Agent.gameObject.GetComponent <NavMeshAgent>().speed        = 15;
         Agent.gameObject.GetComponent <NavMeshAgent>().acceleration = 12;
         return(TaskStatus.Success);
     }
     else
     {
         Agent.GetComponent <NavMeshAgent>().speed = 10;
         Agent.gameObject.GetComponent <NavMeshAgent>().acceleration = 8;
         return(TaskStatus.Failure);
     }
 }