Exemplo n.º 1
0
 void AI_State_Chase()
 {
     aiStates      = AiStates.chase;
     goToPos       = false;
     _lookAtTarget = false;
     _initCheck    = false;
 }
Exemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     controller = GetComponent <EnemyFunctions>();
     corePos    = GameObject.Find("Core").transform;
     targetPos  = null;
     aiState    = AiStates.GoToAndAttackCore;
 }
Exemplo n.º 3
0
 public void ChangeState(AiStates newState)
 {
     if (CurrentState != newState)
     {
         CurrentState = newState;
         states[CurrentState].isInit = false;
     }
 }
Exemplo n.º 4
0
 void AI_State_HasTArget()
 {
     aiStates        = AiStates.hastarget;
     charState.alert = true;
     goToPos         = false;
     _lookAtTarget   = false;
     _initCheck      = false;
 }
 private void OnCollisionEnter2D(Collision2D col) //Checks what objects the AI collides with
 {
     if (col.gameObject.tag == "Tree")            //If the collided object is a tree then continue code here
     {
         treeRef = col.gameObject.GetComponent <TreeFunctions>();
         myState = AiStates.Chopping; //Sets AI state to chopping
     }
 }
Exemplo n.º 6
0
    public void ChangeState(AiStates newState)
    {
        timer.StartTimer(0);
        statesStartTime = timer.currentTime[0];
        currentState    = newState;

        currentAvoidState = AIAvoidState.Null;
    }
Exemplo n.º 7
0
 void AI_State_OnAler_RumListOfBehaviors()
 {
     aiStates      = AiStates.onAlertBehavior;
     charState.run = true;
     goToPos       = false;
     _lookAtTarget = false;
     _initCheck    = false;
 }
Exemplo n.º 8
0
 void AI_State_Normal()
 {
     aiStates        = AiStates.patrol;
     myTarget        = null;
     charState.alert = false;
     goToPos         = false;
     _lookAtTarget   = false;
     _initCheck      = false;
 }
Exemplo n.º 9
0
 //Chase the player until within range
 void ChaseState()
 {
     if (Vector3.Distance(transform.position, player.transform.position) < stopDistance)
     {
         aiState = AiStates.setup;
     }
     else
     {
         GroundTrack(player.transform.position);
         LookAtPlayer();
     }
 }
 private void ChoppingTree()
 {
     if (treeRef != null)
     {
         treeRef.damageTaken  = damage;
         treeRef.beingChopped = true;
     }
     else
     {
         myState = AiStates.Climbing;
     }
 }
    private void Start()
    {
        myState = AiStates.Searching;

        if (movingLeft == true) //If the player is set to move left at the beginning then make sure he is set to face left
        {
            transform.eulerAngles = new Vector3(0, 0, 0);
        }
        else //Otherwise flip the AI
        {
            transform.eulerAngles = new Vector3(0, -180, 0);
        }
    }
Exemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        //Setting the default state to chase
        aiState = AiStates.chase;

        mat = GetComponentInChildren <Renderer>().material;

        //Getting the materials for all pulsable objects
        GameObject[] pulsables;
        pulsables = GameObject.FindGameObjectsWithTag("Pulsable");

        for (int i = 0; i < pulsables.Length; i++)
        {
            pulsableMats[i] = pulsables[i].GetComponent <Renderer>().material;
        }
    }
Exemplo n.º 13
0
    void UpdateAITransitions()
    {
        switch (aiState)
        {
        case AiStates.GoToAndAttackCore:
            if (targetPos != null && distToTarget < Vector3.Distance(transform.position, corePos.position))
            {
                aiState            = AiStates.GoToAndAttackTarget;
                LastSeenTargetTime = Time.time;
            }
            break;

        case AiStates.GoToAndAttackTarget:
            if (Vector3.Distance(transform.position, targetPos.position) > controller.detectionRange && LastSeenTargetTime + controller.stopAttackingTargetTime < Time.time || targetPos.GetComponent <Health>().currentHealth <= 0)
            {
                targetPos = null;
                aiState   = AiStates.GoToAndAttackCore;
            }
            break;
        }
    }
Exemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        switch (curState)
        {
        case AiStates.Wait:
            navSelf.destination = home.position;
            if (Vector3.Distance(this.transform.position, target.position) < searchD)
            {
                curState = AiStates.Chase;
            }
            break;

        case AiStates.Chase:
            navSelf.destination = target.position;
            if (!(Vector3.Distance(this.transform.position, target.position) < searchD))
            {
                curState = AiStates.Alert;
            }
            break;

        case AiStates.Alert:
            if (timer <= 0)
            {
                timer    = 10;
                curState = AiStates.Wait;

                break;
            }
            if ((Vector3.Distance(this.transform.position, target.position) < searchD))
            {
                curState = AiStates.Chase;
            }
            timer -= 1 * Time.deltaTime;
            break;
        }
    }
Exemplo n.º 15
0
 private void Start()
 {
     hearingRadar = GetComponentInChildren <SphereCollider>();
     currentState = AiStates.Idle;
 }
Exemplo n.º 16
0
    // Update is called once per frame
    void Update()
    {
        //Debug.DrawRay(agentCollider.bounds.center, Vector2.right, Color.red);
        //Get TerrainMap
        if (!getTerrain)
        {
            terrainMap = GameObject.FindGameObjectWithTag("TerrainMap").GetComponent <GridSettings>().GetGrid();
            getTerrain = true;
        }

        if (currentState == AiStates.Patrol)
        {
            path.Clear();
            AiAnimations.Walk(agentAnimator);
            if (AiMaths.SightSphere(agentCollider, agentInfo.sightRange, playerMask))
            {
                currentState = AiStates.Chase;
            }

            else if (AiMaths.raycastSides(agentCollider.GetComponent <Collider2D>(), floorMask, (int)transform.localScale.x, gameObject))
            {
                transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
            }

            GetComponent <Rigidbody2D>().velocity = new Vector2(3 * (int)transform.localScale.x, GetComponent <Rigidbody2D>().velocity.y);
        }
        else if (currentState == AiStates.Chase)
        {
            if (KylesFunctions.IsNextToWall2D(transform.localScale.x, agentCollider, 0.5f, playerMask))
            {
                path.Clear();
                currentState = AiStates.Attack;
            }
            else
            {
                AiAnimations.Walk(agentAnimator);



                if (AiMaths.SightSphere(agentCollider, agentInfo.sightRange, playerMask))
                {
                    Vector2 agentNewHeight = new Vector2(GetComponent <CapsuleCollider2D>().bounds.center.x, GetComponent <CapsuleCollider2D>().bounds.center.y - GetComponent <CapsuleCollider2D>().bounds.extents.y);
                    if (!getPlayerPos)
                    {
                        // KylesFunctions.GetXY(agentNewHeight, terrainMap.GetOriginPos(), terrainMap.GetCellSize(), out playerGridPos);
                        KylesFunctions.GetXY(player.transform.position, terrainMap.GetOriginPos(), terrainMap.GetCellSize(), out playerGridPos);
                        getPlayerPos = true;
                    }

                    KylesFunctions.GetXY(agentNewHeight, terrainMap.GetOriginPos(), terrainMap.GetCellSize(), out agentGridPos);
                    KylesFunctions.GetXY(player.transform.position, terrainMap.GetOriginPos(), terrainMap.GetCellSize(), out newPlayerPos);


                    if (newPlayerPos != playerGridPos)
                    {
                        // playerGridPos = newPlayerPos;
                        getPlayerPos = false;
                        path.Clear();
                        findPath = true;
                    }

                    if (path.Count == 0 && !KylesFunctions.IsNextToWall2D(transform.localScale.x, agentCollider, 0.5f, playerMask))
                    {
                        findPath = true;
                    }

                    if (findPath)
                    {
                        KylesFunctions.AStar(terrainMap, agentGridPos.x, agentGridPos.y, playerGridPos.x, playerGridPos.y, 2, false, ref path);
                        findPath = false;
                    }
                }
                else
                {
                    currentState = AiStates.Patrol;
                }
            }
        }
        else if (currentState == AiStates.Attack)
        {
            timer = Time.deltaTime + timer;
            if (!AiMaths.SightSphere(agentCollider, 1.0f, playerMask))
            {
                currentState = AiStates.Chase;
                timer        = 3;
            }

            else if (!isAttacking && timer > 3.0f)
            {
                isAttacking = true;
                audioManager.Play("MantisAttack", gameObject);

                StartCoroutine(DoAttack());
                timer = 0;
            }
            else
            {
                AiAnimations.Walk(agentAnimator);
            }
        }
        else if (currentState == AiStates.AmountOfStates)
        {
        }
    }
Exemplo n.º 17
0
 public void OnGoAlert(Vector3 poi)
 {
     this.pointOfInterest = poi;
     aiStates             = AiStates.alert;
     lookAtPOI            = false;
 }
Exemplo n.º 18
0
 void AI_State_Attack()
 {
     aiStates = AiStates.attack;
 }
Exemplo n.º 19
0
    //Wait for setup time then enter the fire state
    IEnumerator SetupWait()
    {
        yield return(new WaitForSeconds(setupTime));

        aiState = AiStates.fire;
    }