/// <summary>
    /// Generates the random positions and checks if they are validly placed on the navmesh
    /// </summary>
    /// <param name="a_iAmountOfPoints">The amount of patrol points</param>
    /// <param name="a_fRange">The range the points can be generated away from the center point</param>
    private void GeneratePositions(int a_iAmountOfPoints, float a_fRange)
    {
        for (int i = 0; i < a_iAmountOfPoints; i++)                                                                     //Loop through the points
        {
            PatrolPoints ppPatrolPlaceholder = new PatrolPoints();                                                      //Temporary placeholder to add later
            bool         bCanReachTarget     = false;                                                                   //Can the point actually be reached
            while (bCanReachTarget == false)                                                                            //Loop until point is valid
            {
                ppPatrolPlaceholder.SetRandomPos(m_v3PatrolCenter, a_fRange);                                           //Get random position

                NavMeshPath nmpPath = new NavMeshPath();                                                                //Create new nav path
                m_aAgentRef.CalculatePath(ppPatrolPlaceholder.m_v3PatrolPointPosition, nmpPath);                        //

                if (nmpPath.status == NavMeshPathStatus.PathPartial || nmpPath.status == NavMeshPathStatus.PathInvalid) //If path is not valid
                {
                    Debug.Log("Bad Point");
                }
                else
                {
                    bCanReachTarget = true;
                }
            }
            ppPatrolPlaceholder.m_iIndex = i;            //Set index of point
            m_lPatrolPointList.Add(ppPatrolPlaceholder); //Add it to list
        }
    }
    /// <summary>
    /// Finds the nearest neighboring node of each point and creates a "semi coherent" route between them for patrols
    /// </summary>
    /// <param name="a_iIndex">Not used</param>
    /// <returns></returns>
    private int FindNearestUnusedNeighbor(int a_iIndex)
    {
        bool bTestBool           = true;
        int  iNextIndex          = 0;
        int  iInfiniteLoopSafety = 0;

        while (bTestBool)
        {
            PatrolPoints goClosestPoint   = null;//Temp storage for closest Point
            float        fDistanceToPoint = 0.0f;
            foreach (PatrolPoints Point in m_lPatrolPointList)
            {
                if (Point.m_iIndex == iNextIndex || Point.m_bHasBeenLinked)
                {
                    continue;
                }
                if (goClosestPoint == null)
                {
                    //Set first Point to closest, others will compare to this
                    goClosestPoint   = Point;
                    fDistanceToPoint = (Point.m_v3PatrolPointPosition - m_lPatrolPointList[iNextIndex].m_v3PatrolPointPosition).magnitude;
                }
                else
                {
                    //Checks if the current Point is closer than the last one
                    float fdist = (Point.m_v3PatrolPointPosition - m_lPatrolPointList[iNextIndex].m_v3PatrolPointPosition).magnitude;
                    if (fdist < fDistanceToPoint)
                    {
                        //Use the closer Point instead
                        goClosestPoint   = Point;
                        fDistanceToPoint = fdist;
                    }
                }
            }

            if (goClosestPoint == null)
            {
                goClosestPoint = m_lPatrolPointList[0];//For the last node, which wont beable to find a partner node, so it is set to the first one to create a loop
            }

            m_lPatrolPointList[iNextIndex].m_iNextPatrolIndex = goClosestPoint.m_iIndex; //Link partner
            m_lPatrolPointList[iNextIndex].m_bHasBeenLinked   = true;                    //Linked
            iNextIndex = goClosestPoint.m_iIndex;                                        //For the next point in route

            if (RouteFinishCheck())                                                      //If route has finished
            {
                bTestBool = false;                                                       //Exit loop
            }

            //I put this in because I'm an idiot and kept crashing unity.
            iInfiniteLoopSafety++;
            if (iInfiniteLoopSafety > m_iAmountOfPatrolPoints + 10)
            {
                bTestBool = false;
                Debug.Log("InfiniteLoop");
            }
        }
        return(0);
    }
Exemplo n.º 3
0
    // Start is called before the first frame update
    private void Start()
    {
        m_PatrolPointsTarget = new GameObject("GuardTarget");
        m_PatrolPointsTarget.transform.position = transform.position;

        m_ppCurrentPatrolPoint = GetComponent <CS_GuardPatrolManager>().GetSinglePatrolPoint(0);
        GetComponent <NavMeshAgent>().SetAreaCost(14, 1);
    }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the next search point.
 /// </summary>
 public void NextSearchPoint()
 {
     m_iPatrolIndex++;
     if (m_iPatrolIndex >= GetComponent <CS_GuardPatrolManager>().GetAmountOfPoints())
     {
         GetComponent <CS_GuardPatrolManager>().ReCalculatePatrol();
         m_iPatrolIndex = 0;
     }
     m_ppCurrentPatrolPoint = GetComponent <CS_GuardPatrolManager>().GetSinglePatrolPoint(m_ppCurrentPatrolPoint.m_iNextPatrolIndex);
 }
    void Start()
    {
        patrolPoints = GetComponent <PatrolPoints>();
        seeker       = GetComponent <Seeker>();
        ai           = GetComponent <AIPath>();
        player       = GameObject.FindGameObjectWithTag("Player");

        DeterminePath();
        StartCoroutine(DetermineDestinationReached());
    }
    private float m_fInvestigationTimer = 10.0f; //Timer

    private void Awake()
    {
        m_lPatrolPointList = new List <PatrolPoints>();   //Declare patrol list
        PatrolPoints ppPlaceholders = new PatrolPoints(); //Declare patrol list

        //Initialise to prevent other scripts accessing this one from crashing before points have been made.
        for (int i = 0; i < m_iAmountOfPatrolPoints; i++)
        {
            m_lPatrolPointList.Add(ppPlaceholders);
        }
        m_aAgentRef = GetComponent <NavMeshAgent>();
    }
Exemplo n.º 7
0
 public BotContext(BotStat stat,
                   BotSense sense,
                   Rigidbody2D rb2d,
                   Transform transform,
                   Transform aim,
                   PatrolPoints patrolPoints,
                   Weapon weapon)
 {
     this.stat         = stat;
     this.sense        = sense;
     this.rb2d         = rb2d;
     this.transform    = transform;
     this.aim          = aim;
     this.patrolPoints = patrolPoints;
     this.weapon       = weapon;
 }
Exemplo n.º 8
0
    IEnumerator SpawnEnemies()
    {
        GameObject     o  = Instantiate(effectPrefab, spawnLocation);
        ParticleSystem ps = o.GetComponent <ParticleSystem>();

        ps.Play();

        for (int i = 0; i < enemySpawnLimit; ++i)
        {
            var             enemy = Instantiate(prefabEnemy, spawnLocation);
            PatrolPoints    p     = enemy.GetComponent <PatrolPoints>();
            MovementHandler m     = enemy.GetComponent <MovementHandler>();
            if (_PatrolPoints.Count > 0)    //Don't overwrite patrol points with an empty list if one is not provided in the spawner
            {
                m.usePatrolPoints = true;
                p._PatrolPoints   = _PatrolPoints;
            }
            children.Add(enemy);
            yield return(new WaitForSeconds(spawnTime));
        }

        ps.Stop();
        spawnedEnemies = true;
    }
 private PatrolEnemyMovementInput(PatrolPoints patrolPoints, Transform transform)
 {
     _patrolPoints = patrolPoints;
     _transform    = transform;
 }
Exemplo n.º 10
0
 public void NextPatrolPoint()
 {
     m_ppCurrentPatrolPoint = GetComponent <CS_GuardPatrolManager>().GetSinglePatrolPoint(m_ppCurrentPatrolPoint.m_iNextPatrolIndex);
 }
Exemplo n.º 11
0
 public void ResetPointsForInvestigating()
 {
     m_ppCurrentPatrolPoint = GetComponent <CS_GuardPatrolManager>().GetSinglePatrolPoint(0);
     GetComponent <CS_AIAgent>().m_bInterrupt = true;
 }
Exemplo n.º 12
0
 // Start is called before the first frame update
 private void Start()
 {
     m_PatrolPointsTarget   = new GameObject("SpyTarget");
     m_ppCurrentPatrolPoint = GetComponent <CS_GuardPatrolManager>().GetSinglePatrolPoint(0);
 }