Beispiel #1
0
        public int Compare(Cell x, Cell y)
        {
            Vector2 toX = CellExtentions.Direction(x, MyCell);
            Vector2 toY = CellExtentions.Direction(y, MyCell);

            return(toX.sqrMagnitude.CompareTo(toY.sqrMagnitude));
        }
 protected void AddReportedEnemyPosition(Cell pos)
 {
     if (!reportedEnemyPositions.Exists(c => CellExtentions.IsCellEqual(c, pos)))
     {
         reportedEnemyPositions.Add(pos);
         reportedEnemyPositions.Sort(new CellComparerDistanceToMe()
         {
             MyCell = MyCell
         });
     }
 }
        public override void UpdateRole()
        {
            base.UpdateRole();

            if (enemiesInSight.Count > 0)
            {
                if (mySoldier.LookAt(Vector3Extensions.GetPositionWithSmallestDiffAngle(enemiesInSight, mySoldier)))
                {
                    mySoldier.Shoot();
                }

                navAgent.moveToTarget = false;
                underFireCell         = null;
            }
            else if (underFireCell != null)
            {
                mySoldier.LookAt(underFireCell.GetPosition());
                if (CellExtentions.IsCellAngleSmaller(underFireCell, 50, mySoldier))
                {
                    underFireCell = null;
                }
            }
            else if (reportedEnemyPositions.Count > 0)
            {
                mySoldier.LookAt(Vector3Extensions.GetPositionWithSmallestDiffAngle(reportedEnemyPositions, mySoldier));
            }
            else
            {
                if (navAgent.pathGenerated.Count > 0)
                {
                    navAgent.moveToTarget = true;
                    mySoldier.MoveTowards(navAgent.pathGenerated[0]);
                }
                if (backToHome && (navAgent.pathGenerated.Count > 0))
                {
                    mySoldier.LookAt(navAgent.pathGenerated[0]);
                }
                else
                {
                    Vector3 dir = MyCell.GetPosition() + lookAtPos.GetPosition();
                    mySoldier.LookAt(dir);
                }
            }
        }
        public override void UpdateRole()
        {
            base.UpdateRole();

            if (enemiesInSight.Count > 0)
            {
                if (mySoldier.LookAt(Vector3Extensions.GetPositionWithSmallestDiffAngle(enemiesInSight, mySoldier)))
                {
                    mySoldier.Shoot();
                }

                navAgent.moveToTarget = false;
                underFireCell         = null;
            }
            else if (underFireCell != null)
            {
                mySoldier.LookAt(underFireCell.GetPosition());
                if (CellExtentions.IsCellAngleSmaller(underFireCell, 50, mySoldier))
                {
                    underFireCell = null;
                }
            }
            else
            {
                if (navAgent.pathGenerated.Count > 0)
                {
                    navAgent.moveToTarget = true;
                    mySoldier.MoveTowards(navAgent.pathGenerated[0]);
                    mySoldier.LookAt(navAgent.pathGenerated[0]);
                }
                else
                {
                    myTeam.Route.RemoveNextWaypoint();
                    if (!myTeam.Route.IsEmpty())
                    {
                        navAgent.targetCell = myTeam.Route.GetNextWaypoint();
                    }
                }
            }
        }