Exemple #1
0
//State changing away from PURSUE
    void CheckTorch()
    {
        if (currentAgent.isWillInTorchLight() == false)
        {
            protonBeam.fire = false;
            pBeam.SetActive(false);
            currentAgent.anim.SetBool("shoot", false);
            timer = 0;

            //Change colour of torch cone to green
            Color myColor = new Color(0.03f, 0.16f, 0.06f);
            currentAgent.torchCone.GetComponent <Renderer>().material.SetColor("_TintColor", myColor);

            //Will is now out of sight - go to where you last saw Will
            currentAgent.AddPointOfInterest(currentAgent.target.transform.position);

            //Check for points of interest
            if (currentAgent.CheckForPOI() == true)
            {
                currentStateMachine.ChangeState(currentAgent, new GPATROL_Alerted());
            }
            else
            {
                //Default to wander if all else fails
                currentStateMachine.ChangeState(currentAgent, new GPATROL_Wander());
            }

            //More state changing to come
        }
    }
Exemple #2
0
    public void STATE_Update(AgentController agent, StateMachine_GPATROL stateMachine, float deltaTime)
    {
        for (int i = 0; i < agent.GetPOICount(); i++)
        {
            //double distance = System.Math.Sqrt((agent.transform.position.x - agent.GetPositionFromPOI(i).x) * (agent.transform.position.x - agent.GetPositionFromPOI(i).x)
            //                                 + (agent.transform.position.y - agent.GetPositionFromPOI(i).y) * (agent.transform.position.y - agent.GetPositionFromPOI(i).y)
            //                                 + (agent.transform.position.z - agent.GetPositionFromPOI(i).z) * (agent.transform.position.z - agent.GetPositionFromPOI(i).z));


            //some code to ignore broken paths (the agent cant reach the poi so dont send them there)
            NavMeshPath path = new NavMeshPath();
            agent.navAgent.CalculatePath(agent.GetPositionFromPOI(i), path);

            if (path.status == NavMeshPathStatus.PathPartial)
            {
                //Debug.Log("DodgyPath");
                agent.RemovePOI(i);
                break;
            }

            //path good set destination
            agent.navAgent.SetDestination(agent.GetPositionFromPOI(i));

            if ((agent.transform.position - agent.navAgent.destination).magnitude <= agent.torch.range / 2)//this code gets them close enough to spot will if he is around
            {
                agent.RemovePOI(i);

                if (agent.isWillInTorchLight() == true)
                {
                    stateMachine.ChangeState(agent, new GPATROL_Pursue());
                    break;
                }
            }
            else
            {
                if (agent.isWillInTorchLight() == true)
                {
                    stateMachine.ChangeState(agent, new GPATROL_Pursue());
                }
                break;
            }
        }

        //Check if Will is in torchlight
        if (agent.isWillInTorchLight() == true)
        {
            stateMachine.ChangeState(agent, new GPATROL_Pursue());
        }
        else
        {
            //Check if the PointsOfInterest list is empty - if it is then default to Wander
            if (agent.CheckForPOI() == false)
            {
                stateMachine.ChangeState(agent, new GPATROL_Wander());
            }
        }
    }
    public void STATE_Update(AgentController agent, StateMachine_GPATROL stateMachine, float deltaTime)
    {
        #region Visualize the WANDER radius
        if (agent.ShowRadius == true) //If the show radius flag is checked in inspector display the ring
        {
            //Set number of segments
            agent.line.positionCount = segments + 1;

            //Drawing the Circle around the agent to show its search radius
            for (int i = 0; i < segments + 1; i++)
            {
                int angle = (360 / segments) * i;

                agent.line.SetPosition(i, agent.transform.position + agent.wanderRadius * new Vector3(Mathf.Cos(Mathf.Deg2Rad * angle), 0, Mathf.Sin(Mathf.Deg2Rad * angle)));
            }
        }
        #endregion

        if (agent.enableWander == true && Time.timeScale != 0)
        {
            //If the agent doesnt have an INITIAL path then pick a new one
            //This also picks a new one once the agent reaches the end of a path
            if (agent.navAgent.hasPath == false)
            {
                PickNewWanderPoint();
            }

            if (agent.navAgent.hasPath && Vector3.Distance(agent.transform.position, agent.navAgent.destination) <= 0.5)
            {
                agent.navAgent.ResetPath();
            }

            //Check if Will is in torchlight
            if (agent.isWillInTorchLight() == true)
            {
                stateMachine.ChangeState(agent, new GPATROL_Pursue());
            }
            else
            {
                //Check if any points of interest has been registered
                if (agent.CheckForPOI() == true)
                {
                    stateMachine.ChangeState(agent, new GPATROL_Alerted());
                }
            }



            //if (agent.transform.position == agent.navAgent.pathEndPosition)
            //{
            //    waiting = true;
            //    timer += deltaTime;

            //    if (timer >= 1)
            //    {
            //        waiting = false;
            //        timer = 0;
            //    }
            //}
        }
    }