Exemple #1
0
        public static bool IsCellAngleSmaller(Cell destination, float angle, SoldierTeamBlueberry soldier)
        {
            Vector3 myForward  = soldier.transform.forward;
            Vector3 myPosition = soldier.soldier.GetLocation();

            Vector3 dir = destination.GetPosition() - myPosition;

            return(Vector3.Angle(dir, myForward) < angle);
        }
        public TeamRoleBase(SoldierTeamBlueberry mySoldier, Team myTeam)
        {
            this.mySoldier = mySoldier;
            this.myTeam    = myTeam;
            myTeam.AddMember(this);

            NavAgentExample navAgentEx = mySoldier.GetComponent <NavAgentExample>();

            if (navAgentEx)
            {
                GameObject.Destroy(navAgentEx);
            }

            navAgent = mySoldier.GetComponent <NavAgentTeamBlueberry>();
            if (!navAgent)
            {
                navAgent = mySoldier.gameObject.AddComponent <NavAgentTeamBlueberry>();
                navAgent.distanceNeeded = 0.05f;
            }
        }
 public TeamRoleSneaker(SoldierTeamBlueberry mySoldier, Team myTeam) : base(mySoldier, myTeam)
 {
     mySoldier.gameObject.name += "_Sneaker" + myTeam.Name + "_" + MemberIndex;
 }
 public TeamRoleSniper(SoldierTeamBlueberry mySoldier, Team myTeam) : base(mySoldier, myTeam)
 {
     MemberIndex = myTeam.MemberCount;
     mySoldier.gameObject.name += "_Sniper" + myTeam.Name + "_" + MemberIndex;
 }
        public static Vector3 GetPositionWithSmallestDiffAngle(List <IAgent> enemies, SoldierTeamBlueberry soldier)
        {
            List <Vector3> positions = enemies.ConvertAll(e => new Vector3(e.GetLocation().x, e.GetLocation().y, e.GetLocation().z));

            return(Vector3Extensions.GetPositionWithSmallestDiffAngle(positions, soldier));
        }
        public static Vector3 GetPositionWithSmallestDiffAngle(List <Cell> cellPositions, SoldierTeamBlueberry soldier)
        {
            List <Vector3> positions = cellPositions.ConvertAll(c => new Vector3(c.GetPosition().x, c.GetPosition().y, c.GetPosition().z));

            return(Vector3Extensions.GetPositionWithSmallestDiffAngle(positions, soldier));
        }
        public static Vector3 GetPositionWithSmallestDiffAngle(List <Vector3> enemiesPosition, SoldierTeamBlueberry soldier)
        {
            Vector3 myForward     = soldier.transform.forward;
            Vector3 myPosition    = soldier.soldier.GetLocation();
            float   smallestAngle = float.MaxValue;
            Vector3 position      = Vector3.down;

            for (int idx = 0; idx < enemiesPosition.Count; idx++)
            {
                Vector3 dir   = enemiesPosition[idx] - myPosition;
                float   angle = Vector3.Angle(dir, myForward);
                if (angle < smallestAngle)
                {
                    smallestAngle = angle;
                    position      = enemiesPosition[idx];
                }
            }
            return(position);
        }