void stand() { vHorizontal = 0; vVertical = 0; currentState = aiState.Stand; aiStand -= removeAiValue; }
void goRight() { vHorizontal = 1; //hacia la derecha vVertical = 0; currentState = aiState.RunRight; aiRunRight -= removeAiValue; }
void goLeft() { vHorizontal = -1; //hacia la izquierda vVertical = 0; //no volamos currentState = aiState.RunLeft; aiRunLeft -= removeAiValue; }
private void seek(Vector3 _target) { Vector3 targetPos = _target; // get target position Vector3 dVelocity = Vector3.Normalize(targetPos - transform.position) * maxSpeed; // calulate desired velocity Vector3 steer = dVelocity - rb.velocity; // calulate steering vector rb.velocity += steer; // add steering vector to velocity if (steer.sqrMagnitude > 0.0f) { transform.forward = Vector3.Normalize(new Vector3(steer.x, 0, steer.z)); } if (behaviourState == aiState.FOLLOWPATH) { if (Vector3.Distance(transform.position, path[nodeIndex].transform.position) < nodeRadius) { if (nodeIndex >= path.Count - 1) { behaviourState = aiState.CHASEPLAYER; } else { nodeIndex++; } } } }
void jump() { vVertical = 0; //no modificaremos el movimiento horizontal mientras saltamos currentState = aiState.Jump; aiJump -= removeAiValue; if (grounded()) //salto { rb.velocity = Vector3.up * jumpForce * Time.deltaTime * 1000; } }
private void idle() { if (player.GetComponent <AudioSource>().isPlaying&& Vector3.Distance(player.transform.position, transform.position) < soundDist) // if a sound plays { behaviourState = aiState.PATHFIND; // find the player } wanderCounter -= Time.deltaTime; if (wanderCounter <= 0) { wanderLocation = findWanderLocation(); wanderCounter = maxWanderCount; } seek(wanderLocation); }
public void adjustEnemyHealth(int adj) { currHealth += adj; if (currHealth <= 0) { currHealth = 0; state = aiState.DEAD; animController.state = AI_Animation_Controller.animationState.DEAD; } if (currHealth >= maxHealth) { currHealth = maxHealth; } Debug.Log(currHealth); }
// If AI dies, reset and set inactive until time to respawn public void fullReset() { Debug.Log("HERE"); animController.reset(); movement.reset(); state = aiState.ALIVE; ableToSpawn = false; respawnTimer = respawnTimeInSecs; currHealth = maxHealth; GetComponentInChildren <Renderer>().enabled = false; foreach (Collider col in GetComponents <Collider>()) { col.enabled = false; } GetComponent <NavMeshAgent>().enabled = false; GetComponent <Rigidbody>().isKinematic = true; Debug.Log("HERE2"); }
//switches between states public void ChangeState(aiState NewState) { StopAllCoroutines(); CurrentState = NewState; switch (NewState) { case aiState.MOVETO: StartCoroutine(Moveto()); break; case aiState.ATTACK: StartCoroutine(Attack()); break; case aiState.DEAD: StartCoroutine(dead()); break; } }
private void StateLogic() { var distance = Vector3.Distance(selfPos, playerPos); anim.SetInteger("ActionIndex", 0); if (distance >= chaseDist) { //rush at the player untl we walk curState = aiState.chasing; anim.SetBool("Action", true); anim.SetInteger("ActionIndex", 5); anim.SetBool("Moving", false); } else if (distance < chaseDist && distance >= maxAtkRange) { //walk until we're in range to max range atk curState = aiState.walking; anim.SetBool("Action", false); anim.SetBool("Moving", true); } else if (distance < maxAtkRange && distance >= medAtkRange) //do the max range atk { curState = aiState.maxAtk; } else if (distance < medAtkRange && distance >= closeAtkRange) //do the med range atks { curState = aiState.medAtk; } else if (distance < closeAtkRange) //do the close range atk { curState = aiState.closeAtk; } else { anim.SetBool("Action", false); } if (bossHealth.GetHealth() <= 0) { curState = aiState.dead; } }
void StateChecker() { switch (behaviourState) { case (aiState.IDLE): { idle(); break; } case (aiState.PATHFIND): { Debug.Log("Pathing!"); nonNavMesh(); break; } case (aiState.FOLLOWPATH): { seek(path[nodeIndex].transform.position); break; } case (aiState.CHASEPLAYER): { counter -= Time.deltaTime; if (counter <= 0 && Vector3.Distance(transform.position, player.transform.position) > seekDist) { counter = maxCOuntDown; path.Clear(); pathFound = false; behaviourState = aiState.PATHFIND; } seek(player.transform.position); break; } } Invoke("StateChecker", 0.0f); }
private bool ableToSpawn = false; // True if respawnTimer == 0 (except by default as AI already loaded) // Use this for initialization void Start() { if (GetComponent <AI_Animation_Controller>() != null) { animController = GetComponent <AI_Animation_Controller>(); } else { Debug.LogError("You need to add an animation controller to this AI"); } if (GetComponent <AI_Movement>() != null) { movement = GetComponent <AI_Movement>(); } else { Debug.LogError("You need to add an AI_Movement script to this AI"); } player = GameObject.FindGameObjectWithTag("Player"); state = aiState.ALIVE; }
void Awake() { // default states currentState = aiState.following; _attacking = false; _frozen = false; _idle = true; _charging = false; _hasAttacked = false; // Moe attack _areaDamage = transform.FindChild("AreaAttack").gameObject; _chargeDamage = transform.FindChild("FrontAttack").gameObject; _areaDamage.SetActive(false); _chargeDamage.SetActive(false); // navigation _playerTransform = GameObject.FindGameObjectWithTag("Player").transform; _navAgent = GetComponent <NavMeshAgent>(); // etc Components _moeSoundPlayer = GetComponent <AudioSource>(); _moeAnimator = GetComponent <Animator>(); _moeAttack = Animator.StringToHash("Attack"); _moeCharge = Animator.StringToHash("Charging"); _moeIdle = Animator.StringToHash("Idling"); // Getting the materials on Moe's body that can change to stone, and making them invisible _partsToTurnToStone = new Material[moeSkin.Length]; for (int i = 0; i < moeSkin.Length; i++) { _partsToTurnToStone[i] = moeSkin[i].materials[1]; _partsToTurnToStone[i].color = new Color(1f, 1f, 1f, 0f); } ChangeState(aiState.following); }
void Awake () { // default states currentState = aiState.following; _attacking = false; _frozen = false; _idle = true; _charging = false; _hasAttacked = false; // Moe attack _areaDamage = transform.FindChild("AreaAttack").gameObject; _chargeDamage = transform.FindChild("FrontAttack").gameObject; _areaDamage.SetActive(false); _chargeDamage.SetActive(false); // navigation _playerTransform = GameObject.FindGameObjectWithTag("Player").transform; _navAgent = GetComponent<NavMeshAgent>(); // etc Components _moeSoundPlayer = GetComponent<AudioSource>(); _moeAnimator = GetComponent<Animator>(); _moeAttack = Animator.StringToHash("Attack"); _moeCharge = Animator.StringToHash("Charging"); _moeIdle = Animator.StringToHash("Idling"); // Getting the materials on Moe's body that can change to stone, and making them invisible _partsToTurnToStone = new Material[moeSkin.Length]; for(int i = 0; i < moeSkin.Length; i++) { _partsToTurnToStone[i] = moeSkin[i].materials[1]; _partsToTurnToStone[i].color = new Color(1f, 1f, 1f, 0f); } ChangeState(aiState.following); }
public void ChangeState(aiState moeState) { currentState = moeState; switch (currentState) { case aiState.following: break; case aiState.stoned: StartCoroutine(TurnToStone()); break; case aiState.attacking: if (_frozen) { ChangeState(aiState.stoned); return; } StartCoroutine(AttackBugCheck()); StartCoroutine(Attack()); break; case aiState.charging: StartCoroutine(Charge()); break; case aiState.stopped: StopMoe(); break; default: ChangeState(aiState.following); break; } }
private void nonNavMesh() { if (!pathFound) // if a path hasn't been found { if (path.Count == 0) { zombieClosest = findClosestNodetoObject(this.gameObject); // find closest node to zombie playerClosest = findClosestNodetoObject(player); // find closest node to player path.Add(zombieClosest); // add the closest to path if (zombieClosest.name == playerClosest.name) { behaviourState = aiState.CHASEPLAYER; } } //potentialDirection is now a local list, cleans up code in memory. List <GameObject> potentialDirection = new List <GameObject>(); potentialDirection = path[path.Count - 1].GetComponent <nodeScript>().attachedNodes; // gets attached nodes ** NOTE ** Getcomponents kill performance.... if (potentialDirection.Count == 1) // if only one attached node { path.Add(potentialDirection[0]); // add the node } else { List <GameObject> pickList = new List <GameObject>(); //pickList.Clear(); // clear the pick list for (int i = 0; i < potentialDirection.Count; i++) { if (!path.Contains(potentialDirection[i])) // if the potential node is not on the path { pickList.Add(potentialDirection[i]); // add to pick list } } GameObject addItem = null; float distance = Mathf.Infinity; for (int i = 0; i < pickList.Count; i++) { Vector3 dist = pickList[i].transform.position - playerClosest.transform.position; // subtract the position of the pick list form the closest node float cDist = dist.sqrMagnitude; // calulate the square mag if (cDist < distance) // if the new distance is shorter than the old distance { addItem = pickList[i]; // set current path add distance = cDist; // se new shortest distance } } path.Add(addItem); // add item to path } if (path[path.Count - 1] == playerClosest) // if the last item on the path is the closest node to player { pathFound = true; // set path to found } } if (pathFound) { behaviourState = aiState.FOLLOWPATH; // change AI state } }
void climb() { currentState = aiState.Climb; aiClimb -= removeAiValue; }
public void ChangeState(aiState moeState) { currentState = moeState; switch(currentState) { case aiState.following: break; case aiState.stoned: StartCoroutine(TurnToStone()); break; case aiState.attacking: if (_frozen) { ChangeState(aiState.stoned); return; } StartCoroutine(AttackBugCheck()); StartCoroutine(Attack()); break; case aiState.charging: StartCoroutine(Charge()); break; case aiState.stopped: StopMoe(); break; default: ChangeState(aiState.following); break; } }
void LoseTarget() { state = aiState.Patrol; ai.DScurve = patrollingCurve; target = null; }
// Update is called once per frame void Update() { detection(); //funcion de deteccion del entorno stateMachine(); //funcion de maquina de estados if (enlace.GetComponent<Player>().objetivos.Count > 0) //se mira si hay objetivos o no { estado = aiState.attacking; //estado de atacar } else { estado = aiState.wandering; //estado de vagar por el mapa } }
// Use this for initialization void Start() { if (!this.gameObject.GetComponent<RTSObject>().owner.human) { // Se comprueba si el propietario es el jugador(human) GetComponent<MovimientoAleatorioCivil>().enabled = true; GetComponent<ADS>().enabled = true; speed = 2; hit = new RaycastHit(); estado = aiState.wandering; enlace = GameObject.Find("EnemyPlayer1"); anim = gameObject.GetComponent<Animator>(); } else { GetComponent<MovimientoAleatorioCivil>().enabled = false; GetComponent<ADS>().enabled = false; } }
void AcquiredTarget(Transform target) { this.target = target; state = aiState.Attack; ai.DScurve = attackCurve; }
protected void StopAttack() { state = aiState.Patrol; ai.DScurve = patrollingCurve; }