Example #1
0
        // private AgentAgentHelper AgentHelper = new AgentAgentHelper();

        public override void Initialize()
        {
            Time.timeScale = 1;
            // Debug.Log(Thread.CurrentThread.ManagedThreadId);
            //Random.seed = Thread.CurrentThread.ManagedThreadId;
            team                 = this.gameObject.tag;
            initial_position     = this.transform.position;
            initial_rotation     = this.transform.rotation;
            parent               = this.transform.parent;
            ball                 = parent.Find("Soccer Ball").gameObject;
            m_BehaviorParameters = gameObject.GetComponent <BehaviorParameters>();
            car_controller       = GetComponent <CarController>();
            self_rBody           = GetComponent <Rigidbody>();
            ball_rBody           = ball.GetComponent <Rigidbody>();
            goalCheck            = ball.GetComponent <GoalCheck>();
            GameObject car_sphere = this.transform.Find("Sphere").gameObject;

            if (team == "Blue")
            {
                car_sphere.GetComponent <Renderer>().material.SetColor("_Color", Color.blue);
                own_goal   = parent.Find("Blue_goal").gameObject;
                other_goal = parent.Find("Red_goal").gameObject;
                friends    = new List <GameObject>();

                foreach (GameObject go in AgentHelper.FindGameObjectInChildWithTag(parent, team))
                {
                    if (go.Equals(this.gameObject)) // I do this to exclude itself (not sure if its a good idea yet)
                    {
                        continue;
                    }
                    friends.Add(go);
                }
                enemies = new List <GameObject>(AgentHelper.FindGameObjectInChildWithTag(parent, "Red"));
            }
            else if (team == "Red")
            {
                car_sphere.GetComponent <Renderer>().material.SetColor("_Color", Color.red);
                own_goal   = parent.Find("Red_goal").gameObject;
                other_goal = parent.Find("Blue_goal").gameObject;
                friends    = new List <GameObject>();
                foreach (GameObject go in AgentHelper.FindGameObjectInChildWithTag(parent, team))
                {
                    if (go.Equals(this.gameObject)) // I do this to exclude itself (not sure if its a good idea yet)
                    {
                        continue;
                    }
                    friends.Add(go);
                }
                enemies = new List <GameObject>(AgentHelper.FindGameObjectInChildWithTag(parent, "Blue"));
            }
        }
Example #2
0
        // SlipLimit = 0.3 apparently

        private void Start()
        {
            // get the car controller
            WheelColliders = GetComponentsInChildren <WheelCollider>();

            ball            = GameObject.FindGameObjectWithTag("Ball");
            m_Car           = GetComponent <CarController>();
            terrain_manager = terrain_manager_game_object.GetComponent <TerrainManager>();
            who_ball        = ball.GetComponent <WhoBall>();
            goal_check      = ball.GetComponent <GoalCheck>();



            // note that both arrays will have holes when objects are destroyed
            // but for initial planning they should work
            friend_tag = gameObject.tag;
            if (friend_tag == "Blue")
            {
                enemy_tag      = "Red";
                own_goalNormal = new Vector3(1, 0, 0);
            }
            else
            {
                enemy_tag      = "Blue";
                own_goalNormal = new Vector3(-1, 0, 0);
            }
            friends = GameObject.FindGameObjectsWithTag(friend_tag);
            enemies = GameObject.FindGameObjectsWithTag(enemy_tag);



            behaviorTree = new Root(
                new Selector(
                    new BlackboardCondition("OtherTeamAttack", Operator.IS_EQUAL, true, Stops.SELF,
                                            new Selector(
                                                new Condition(new Func <bool>(() => CheckDefPos()),
                                                              new Sequence(
                                                                  new Action(() => BearingBall()),
                                                                  new Action(() => InterceptBall())
                                                                  )
                                                              ),
                                                new Sequence(
                                                    new Action(() => BearingCar()),
                                                    new Action(() => InterceptEnemy())
                                                    )

                                                )
                                            ),

                    new Selector(
                        new Condition(new Func <bool>(() => CheckShooter()),
                                      new Sequence(
                                          new Action(() => BearingBallTraj()),
                                          new Action(() => AlignToBall())
                                          )

                                      ),
                        new Action(() => SupportRealign())
                        )

                    )
                );

            blackboard = behaviorTree.Blackboard;


#if UNITY_EDITOR
            Debugger debugger = (Debugger)this.gameObject.AddComponent(typeof(Debugger));
            debugger.BehaviorTree = behaviorTree;
#endif
        }