Ejemplo n.º 1
0
    public void setState(guardState state)
    {
        curState        = state;
        rotater.enabled = false;
        switch (state)
        {
        case guardState.Patrol:
            target = pathNodes[pathNodeHelper];     // continue to last node
            break;

        case guardState.Chase:
            if (!alerted)
            {
                alerted = true;
                speed  *= 1.5f;
            }
            target = thief;
            break;

        case guardState.Search:
            Debug.Log("Search state");
            target = lastSeenPosTrans;
            break;

        case guardState.Look:
            rotater.timeToRotate.setTimer(2f);
            rotater.enabled = true;
            break;
        }
    }
Ejemplo n.º 2
0
 private void Searching()
 {
     isCurrently = guardState.searching;
     guardAnimator.SetBool("isIdling", true);
     guardAnimator.SetBool("isWalking", false);
     guardAnimator.SetBool("isShooting", false);
     totalSearchTimer = 0f;
     nextTurnTime     = GetNextTurnTime(0);
 }
Ejemplo n.º 3
0
 internal void Shooting()
 {
     isCurrently = guardState.shooting;
     guardAnimator.SetBool("isIdling", false);
     guardAnimator.SetBool("isWalking", false);
     guardAnimator.SetBool("isShooting", true);
     agent.isStopped = true;
     agent.velocity  = new Vector3(0, 0, 0);
     totalDrawTimer  = 0f;
 }
    void SwitchToState(guardState newState)
    {
        switch (newState)
        {
        case guardState.Patrol:
            break;

        case guardState.Pursue:
            navMeshAgent.SetDestination(target.transform.position);

            break;

        default:
            break;
        }
        currentState = newState;
    }
Ejemplo n.º 5
0
 internal void Patrolling()
 {
     if (isCurrently != guardState.patrolling)
     {
         nextPoint = patrolPoints[Random.Range(0, patrolPoints.Length)];
         if (!nextPoint.activeSelf)
         {
             Patrolling();
         }
         else
         {
             nextPoint.SetActive(false);
             agent.SetDestination(new Vector3(nextPoint.transform.position.x, guardsY, nextPoint.transform.position.z));
             isCurrently = guardState.patrolling;
             guardAnimator.SetBool("isIdling", false);
             guardAnimator.SetBool("isWalking", true);
             guardAnimator.SetBool("isShooting", false);
         }
     }
 }
Ejemplo n.º 6
0
 // Start is called before the first frame update
 void Start()
 {
     isCurrently       = guardState.idle;
     speed             = 20;
     fieldOfViewRadius = 20;
     fieldOfViewAngle  = 90;
     timeToDraw        = 2;
     //agent = gameObject.AddComponent<NavMeshAgent>();
     agent = GetComponent <NavMeshAgent>();
     //agent.nextPosition = transform.position;
     agent.speed      = speed;
     patrolPoints     = GameObject.FindGameObjectsWithTag("Patrol Point");
     nextPoint        = patrolPoints[0];
     searchTime       = 5;
     nextTurnTime     = 0;
     turningSpeed     = 90;
     turningDirection = 1;
     guardsY          = 0f;
     guardAnimator    = GetComponent <Animator>();
     guardAnimator.SetBool("isIdling", true);
     guardAnimator.SetBool("isWalking", false);
     guardAnimator.SetBool("isShooting", false);
 }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (positioned == 20)
        {
            transform.position = startingPosition;
        }
        positioned++;

        switch (isCurrently)
        {
        case guardState.patrolling:
        {
            if (DoISeePlayer())
            {
                Debug.Log("I See Player");
                Shooting();
            }
            if (transform.position == agent.destination)
            {
                nextPoint.SetActive(true);
                Searching();
            }
        }
        break;

        case guardState.searching:
        {
            if (DoISeePlayer())
            {
                Debug.Log("I See Player");
                Shooting();
            }
            transform.Rotate(Vector3.up, turningSpeed * Time.deltaTime * turningDirection);         //direction indicates on which side he turns
            if (totalSearchTimer > nextTurnTime)
            {
                turningDirection *= -1;
                nextTurnTime      = GetNextTurnTime(nextTurnTime);
            }

            totalSearchTimer += Time.deltaTime;
            if (totalSearchTimer > searchTime)
            {
                Patrolling();
            }
        }
        break;

        case guardState.shooting:
        {
            Vector3 dirToPlayer = (myManager.GetPlayerPosition() - transform.position).normalized;
            transform.forward = new Vector3(dirToPlayer.x, 0, dirToPlayer.z);
            if (DoISeePlayer())
            {
                totalDrawTimer += Time.deltaTime;
                if (totalDrawTimer > timeToDraw)
                {
                    Shoot();
                }
            }
            else
            {
                agent.isStopped = false;
                isCurrently     = guardState.patrolling;
                guardAnimator.SetBool("isIdling", false);
                guardAnimator.SetBool("isWalking", true);
                guardAnimator.SetBool("isShooting", false);
            }
        }
        break;
        }
    }