Exemple #1
0
 public void ResumePatrolling()
 {
     shouldPatrol = true;
     patrolBehaviorState = PatrolBehaviorState.WaitingForNextMove;
     //	UpdateMovingToNextPatrolPoint();
     UpdateWaitingForNextMove();
     fsm.state = FiniteStateMachine.State.Patrol;
 }
Exemple #2
0
    IEnumerator SetWayPoints()
    {
        TileHandler tileHandler = GameObject.FindGameObjectWithTag("TileHandler").GetComponent<TileHandler>();

        while(!tileHandler.tileMapComplete){
            yield return null;
        }

        for (int i = 0; i < patrolPoints.Length; i++){
            Tile tile = tileHandler.GetWalkableTile();
            patrolPoints[i] = tile.transform;
        }

        print ("patrol points set");
        patrolPointIndex = 0;
        patrolBehaviorState = PatrolBehaviorState.MovingToNextPatrolPoint;
        timeToWaitBeforeNextMove = -1.0f;
        destination = patrolPoints [patrolPointIndex+1];
        directionVector = destination.position - transform.position;
    }
Exemple #3
0
    void UpdateWaitingForNextMove()
    {
        timeToWaitBeforeNextMove -= Time.deltaTime;
        Quaternion newRot = Quaternion.LookRotation(destination.position - transform.position);
        transform.rotation = Quaternion.Slerp(transform.rotation, newRot, Time.deltaTime * 10f);
        if (timeToWaitBeforeNextMove < 0.0f)
        {
            ChooseNextDestination();

            if (patrolPointIndex == patrolPoints.GetLength(0)-1){
                destination = patrolPoints[0];
            }
            else if (patrolPointIndex == patrolPoints.GetLength(0)){
                destination = patrolPoints[1];

            }
            else{
                destination = patrolPoints[patrolPointIndex+1];
            }
            pathRequested = false;
            patrolBehaviorState = PatrolBehaviorState.MovingToNextPatrolPoint;

        }
    }
Exemple #4
0
    void UpdateMovingToNextPatrolPoint()
    {
        Vector3 currentDestination = GetCurrentDestination();

        Quaternion newRot = Quaternion.LookRotation(currentDestination - transform.position);
        transform.rotation = Quaternion.Slerp(transform.rotation, newRot, Time.deltaTime * 10f);
        //transform.forward = currentDestination - transform.position;
        //transform.Translate(Vector3.forward * patrolWalkSpeed * Time.deltaTime);

        if (!pathRequested){
            pathRequested = true;
            enemy.MakeRequest(currentDestination);
        }

        if (enemy.destinationReached){
            enemy.destinationReached = false;
            timeToWaitBeforeNextMove = Random.Range(delayAtPatrolPointMin, delayAtPatrolPointMax);
            patrolBehaviorState = PatrolBehaviorState.WaitingForNextMove;
        }
    }