Beispiel #1
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "agent")
     {
         TargetAgent t = other.GetComponent <TargetAgent>();
         if (!t.isBreeding && canBreed && t.canBreed && TargetManager.Instance.nbTarget < 50)
         {
             TargetManager.Instance.nbTarget++;
             isBreeding = true;
             canBreed   = false;
             Invoke("StopBreeding", 2f);
             GameObject o = Instantiate(targetPrefab, transform.position + new Vector3(Random.Range(-2f, 2f), Random.Range(-2f, 2f), 0), Quaternion.identity);
             o.transform.localScale = Vector3.zero;
             o.GetComponent <TargetAgent>().transform.DOScale(1, 2f);
             o.GetComponent <TargetAgent>().mouseObject = mouseObject;
             o.GetComponent <TargetAgent>().GiveBrain(brain);
             if (!(o.transform.position.x > -9.8f &&
                   o.transform.position.x < -9.8f &&
                   o.transform.position.y > -4.8f &&
                   o.transform.position.y < 4.8f))
             {
                 o.transform.position = new Vector3(0, 0, originalZ);
             }
         }
     }
 }
Beispiel #2
0
    public void CreateTarget(GameObject prefab)
    {
        GameObject targetSpawn = Instantiate(spawnPoint) as GameObject;

        targetSpawn.transform.position = new Vector3(2.3f, 0.05f, 2.3f);

        GameObject  target      = Instantiate(prefab, targetSpawn.transform.position, Quaternion.Euler(0, -150, 0));
        TargetAgent targetAgent = target.GetComponent <TargetAgent>();

        targetAgent.name = "Target";
    }
Beispiel #3
0
 public override void AcademyReset()
 {
     //navMesh.RemoveData();
     Destroy(mazeInstance.gameObject);
     mazeInstance = Instantiate(mazePrefab) as Maze;
     mazeInstance.Generate();
     navMesh = floor.GetComponent <NavMeshSurface>();
     navMesh.BuildNavMesh();
     targetAgent = target.GetComponent <TargetAgent>();
     targetAgent.Reset();
 }
Beispiel #4
0
 //used by MLAgents to set everything up
 public override void InitializeAgent()
 {
     base.InitializeAgent();
     huntAcademy = FindObjectOfType <HuntAcademy>();
     floor       = huntAcademy.floor;
     hunterAgents.Add(this);
     startPosition        = transform.position;
     rb                   = GetComponent <Rigidbody>();
     rayPer               = GetComponent <RayPerception>();
     targetAgent          = target.GetComponent <TargetAgent>();
     lastDistanceToTarget = Vector3.Distance(transform.position, target.transform.position);
 }
Beispiel #5
0
        private void SetLocationByStep(double[] netResult, ShipAgent ship, TargetAgent target)
        {
            if (Math.Abs(ship.Location.X - target.Location.X) <= 1 && Math.Abs(ship.Location.Y - target.Location.Y) <= 1)
            {
                ship.Location = target.Location;
            }
            else
            {
                ship.PrevPosition = new Position()
                {
                    X = ship.Location.X, Y = ship.Location.Y
                };

                int maxNetResultIndex = GetMaxResultIndex(netResult);

                switch (ship.DirectionToTarget)
                {
                case Direction.NW:
                    if (maxNetResultIndex == 0)
                    {
                        ship.Location.X -= 1;
                    }
                    if (maxNetResultIndex == 1)
                    {
                        ship.Location.X -= 1; ship.Location.Y -= 1;
                    }
                    if (maxNetResultIndex == 2)
                    {
                        ship.Location.Y -= 1;
                    }
                    break;

                case Direction.W:
                    if (maxNetResultIndex == 0)
                    {
                        ship.Location.X -= 1; ship.Location.Y += 1;
                    }
                    if (maxNetResultIndex == 1)
                    {
                        ship.Location.X -= 1;
                    }
                    if (maxNetResultIndex == 2)
                    {
                        ship.Location.X -= 1; ship.Location.Y -= 1;
                    }
                    break;

                case Direction.SW:
                    if (maxNetResultIndex == 0)
                    {
                        ship.Location.Y += 1;
                    }
                    if (maxNetResultIndex == 1)
                    {
                        ship.Location.X -= 1; ship.Location.Y += 1;
                    }
                    if (maxNetResultIndex == 2)
                    {
                        ship.Location.X -= 1;
                    }
                    break;

                case Direction.S:
                    if (maxNetResultIndex == 0)
                    {
                        ship.Location.X += 1; ship.Location.Y += 1;
                    }
                    if (maxNetResultIndex == 1)
                    {
                        ship.Location.Y += 1;
                    }
                    if (maxNetResultIndex == 2)
                    {
                        ship.Location.X -= 1; ship.Location.Y += 1;
                    }
                    break;

                case Direction.SE:
                    if (maxNetResultIndex == 0)
                    {
                        ship.Location.X += 1;
                    }
                    if (maxNetResultIndex == 1)
                    {
                        ship.Location.X += 1; ship.Location.Y += 1;
                    }
                    if (maxNetResultIndex == 2)
                    {
                        ship.Location.Y += 1;
                    }
                    break;

                case Direction.E:
                    if (maxNetResultIndex == 0)
                    {
                        ship.Location.X += 1; ship.Location.Y -= 1;
                    }
                    if (maxNetResultIndex == 1)
                    {
                        ship.Location.X += 1;
                    }
                    if (maxNetResultIndex == 2)
                    {
                        ship.Location.X += 1; ship.Location.Y += 1;
                    }
                    break;

                case Direction.NE:
                    if (maxNetResultIndex == 0)
                    {
                        ship.Location.Y -= 1;
                    }
                    if (maxNetResultIndex == 1)
                    {
                        ship.Location.X += 1; ship.Location.Y -= 1;
                    }
                    if (maxNetResultIndex == 2)
                    {
                        ship.Location.X += 1;
                    }
                    break;

                case Direction.N:
                default:
                    if (maxNetResultIndex == 0)
                    {
                        ship.Location.X -= 1; ship.Location.Y -= 1;
                    }
                    if (maxNetResultIndex == 1)
                    {
                        ship.Location.Y -= 1;
                    }
                    if (maxNetResultIndex == 2)
                    {
                        ship.Location.X += 1; ship.Location.Y -= 1;
                    }
                    break;
                }

                if (_depthsMap.GetLength(0) <= ship.Location.Y ||
                    _depthsMap.GetLength(1) <= ship.Location.X ||
                    ship.Location.X < 0 || ship.Location.Y < 0)
                {
                    ship.Location = new Position()
                    {
                        X = ship.PrevPosition.X, Y = ship.PrevPosition.Y
                    };
                }
            }
        }