Esempio n. 1
0
 public void SetStateToRoamPlayer()
 {
     if (currentState != aiStates.RoamPlayer)
     {
         //A search logic could be implemented here...
         currentState = aiStates.RoamPlayer;
     }
 }
Esempio n. 2
0
 // Start is called before the first frame update
 void Start()
 {
     audioDistortionFilter = GetComponent <AudioDistortionFilter>();
     agent              = GetComponent <NavMeshAgent>();
     currentState       = aiStates.patrolling;
     transform.position = points[0].transform.position;
     nextPoint          = 1;
     destination        = points[nextPoint];
 }
Esempio n. 3
0
 public void SetStateToChase()
 {
     if (currentState != aiStates.Chase)
     {
         currentState = aiStates.Chase;
         MoveTarget();
     }
     else
     {
         MoveTarget();
     }
 }
    void Start ()
	{
        currentState = aiStates.OBSTACLE_AVOID;

		laneSystem = GameObject.FindGameObjectWithTag ("LaneSystem").GetComponent<LaneSystem> ();

		turnLeft = turnRight = false;
		goForward = true;
		rb = GetComponent<Rigidbody> ();

//		InputController.Instance.SetAI (true);
		aiController = GetComponent<AIInputController> ();
		prevPosition = transform.position;
		laneManager = GetComponent<AILaneManager> ();
		offTrack = false;
	}
Esempio n. 5
0
 void determineState()
 {
     if (alwaysChase)
     {
         currentState = aiStates.chasing;
     }
     else if (neverChase)
     {
         currentState = aiStates.patrolling;
     }
     else if (seesPlayer)
     {
         currentState = aiStates.chasing;
     }
     else
     {
         currentState = aiStates.patrolling;
     }
 }
    // Update is called once per frame
    void Update()
    {
        // Make sure our new move position is safe
        if (!Physics.Raycast(transform.position, -Vector3.up, 1.0f))
        {
            // Position is not safe so go back to old position
            transform.position = OldPosition;
        }

        if (targetPlayer == null)
            targetPlayer = GameObject.FindGameObjectWithTag ("Player");

        Vector3 rayCastOrigin = new Vector3(0.0f, 2.0f, 0.0f);

        RaycastHit hit;
        Ray lineOfSight = new Ray(gameObject.transform.position + rayCastOrigin, targetPlayer.transform.position - (gameObject.transform.position + rayCastOrigin));

        Debug.DrawRay(lineOfSight.origin,lineOfSight.direction*lineOfSightRange);

        if (Physics.Raycast(lineOfSight, out hit, lineOfSightRange, masksToUse))
        {
            if (hit.transform.gameObject.tag == "Player")
            {
                aiState = aiStates.follow;

                float tempDistance = Vector3.Distance(hit.transform.position, gameObject.transform.position);

                if (tempDistance < attackRange)
                {
                    aiState = aiStates.attack;
                }
            }
            else
            {
                if (patrolPoints.GetLength(0) == 0)
                {
                    aiState = aiStates.returnToPosition;
                }
                else
                {
                    aiState = aiStates.patrol;
                }
            }
        }
        else
        {
            if (patrolPoints.GetLength(0) == 0)
            {
                aiState = aiStates.returnToPosition;
            }
            else
            {
                aiState = aiStates.patrol;
            }
        }

        switch (aiState)
        {
            case aiStates.follow:
                target = targetPlayer.transform.position;
                if(agent.isOnNavMesh){
                    agent.SetDestination(target);
                }

                playerSeen = true;

                rigAnimation.SetBool("Attack", false);

                break;

           case aiStates.patrol:
                target = patrolPoints[currentPatrolNode].transform.position;

                if(agent.isOnNavMesh)
                    agent.SetDestination(target);

                Vector3 tempVector = transform.position - patrolPoints[currentPatrolNode].transform.position;

                if (tempVector.magnitude < 1.0f)
                {
                    currentPatrolNode++;
                    if (currentPatrolNode == patrolPoints.Length)
                    {
                        currentPatrolNode = 0;
                    }
                }

                rigAnimation.SetBool("Attack", false);

                playerSeen = false;
                break;

           case aiStates.returnToPosition:
                if(agent.isOnNavMesh)
                    agent.SetDestination(original);

                playerSeen = false;

                rigAnimation.SetBool("Attack", false);
                break;

            case aiStates.attack:

                if(!isBig)
                {
                    if(agent.isOnNavMesh)
                        agent.SetDestination(transform.position);
                }

                if (attackTimer >= attackCooldown)
                {
                    rigAnimation.SetBool("Attack", true);
                    PlayerStats hitStats =  hit.transform.gameObject.GetComponent<PlayerStats>();
                    hitStats.SendMessage("ModifyHealth", -attackDamage);
                    if(canSlow)
                    hitStats.DebuffPlayer();

                    attackTimer = 0.0f;
                }
                else
                {
                    attackTimer += Time.deltaTime;
                }
                playerSeen = false;
                break;

            default:
                Debug.LogError("AI state not set correctly");
                break;
        }

        // Store current position
        OldPosition = agent.nextPosition;
    }