public virtual void ChangeState(enemyState newState) { if (currentState != newState) { currentState = newState; } }
private void ResetEnemyState() { aIPath.maxSpeed = initialSpeed; timeChasing = 0; aIPath.canMove = true; currentState = enemyState.CHASING; }
IEnumerator NextPatrolPointDelay() { while (true) { if (currentAlarmState == enemyState.NotAlarmed) { if (currentGuardPointToGo == 1) { currentGuardPointToGo = 2; currentPoint = gaurdPoint2; gameObject.GetComponent <NavMeshAgent>().enabled = true; currentMovementState = enemyState.Patrolling; } else { currentGuardPointToGo = 1; currentPoint = gaurdPoint; gameObject.GetComponent <NavMeshAgent>().enabled = true; currentMovementState = enemyState.Patrolling; } } yield return(new WaitForSeconds(patrolDelay)); } }
private void moute() { if (!hasTarget) return; if (stopMoving) return; Vector3 movement = Vector3.zero; navi.SetDestination(target.position); Vector3 nextstep = navi.nextPosition; movement = nextstep - transform.position; movement.y = 0; float dist = movement.magnitude; if( navi.velocity.sqrMagnitude < 0.5 ) { _enemyState = enemyState.idle; } else { movement = movement.normalized * speed; _enemyState = enemyState.move; } //float step = speed * Time.deltaTime; //transform.position = Vector3.MoveTowards(transform.position, target.position, step); }
// Checks if player is in unobstructed view for the enemy void CheckSight() { RaycastHit hit; /// <summary> /// create a line starting at enemy position and ending at 'target' position and returns true when the line hits anything on the way /// Linecast automatically ignores colliders in the layer "IgnoreRaycast" /// Bullets and pickups should be placed in this layer, so enemy doesn't lose sight of player when it shoots /// </summary> if (Physics.Linecast(transform.position, target.position, out hit)) { // if the collider hit by linecast is tagged Player... if (hit.collider.tag == "Player") { // ... set sighted to true; commence attacking targetSighted = true; currentState = enemyState.attacking; } // otherwise... else { // target not sighted; back to idling targetSighted = false; currentState = enemyState.idle; } } }
private void OnCollisionEnter(Collision collision) { if (collision.collider.tag == "PathNode") { currentState = enemyState.idle; } }
// Update is called once per frame void Update() { Direction = Target.transform.position - this.transform.position; if (Direction.magnitude > 1.2f) { Direction.Normalize(); } else { currentState = enemyState.idle; if (Target == Player) { transform.position = myGameManager.transform.position; gameObject.GetComponent <Respawn_Timer>().StartCountdown(); myGameManager.startBattle(health); } } findPlayer(); if (currentState != enemyState.idle) { moveToTarget(); } if (currentState != previousState) { previousState = currentState; } }
IEnumerator Attack() { ReadySpear.SetActive(false); attackKickSpear.SetActive(true); Debug.Log("Attack"); anim.SetBool("isAttacking", true); anim.SetTrigger("attack"); yield return(new WaitForSeconds(0.60f)); spearKillCollider.enabled = true; if (currentCombatState != enemyState.Stunned) { yield return(new WaitForSeconds(0.50f)); spearKillCollider.enabled = false; yield return(new WaitForSeconds(0.65f)); attackKickSpear.SetActive(false); anim.SetBool("isAttacking", false); if (currentCombatState != enemyState.Stunned) { currentCombatState = enemyState.Ready; } } // 0.75 is when box collider should be on // 1.75 overall }
private IEnumerator aksi() { if (action) { yield break; } action = true; Vector3 targetpos = new Vector3(atktarget.transform.position.x - 1.5f, atktarget.transform.position.y, atktarget.transform.position.z); while (movetarget(targetpos)) { yield return(null); } DoDamage(); yield return(new WaitForSeconds(0.5f)); Vector3 spos = ipos; while (moveipos(spos)) { yield return(null); } BSM.action.RemoveAt(0); BSM.bs = BattleSM.battleState.WAIT; action = false; curState = enemyState.PROCESSING; }
// Update is called once per frame void Update() { switch (GameManager.gameState) { case GameManager.GameState.PLAYING: float dist = Vector3.Distance(player.position, transform.position); LookAtPlayer(); DistCheck(dist); switch (state) { case enemyState.CHASING: Move(); break; case enemyState.ATTACKING: _rb.velocity = Vector3.zero; spawnHitbox(); if (dist > stoppingDistance) { state = enemyState.CHASING; } break; } break; } }
public virtual void StateWonder() { // if agent not walking, make him walk if (_agent.enabled == false) { if (_animator != null && GetAnimation(_animatorBools[1]) == false) { StartAgent(RandomWonderPos()); SetAnimation(_animatorBools[1]); StartCoroutine(CR_Wonder()); } } // if agent reached his destination, then aim to attack else { if (_agent.hasPath == true) { AgentLookAtPath(); } else { _state = enemyState.aim; } } }
protected void changeState(enemyState newState) { if (!newState.Equals(currentState)) { currentState = newState; } }
void EnemyHearing() { // Check to see if player is knocking only if not searching if (curEnemyState != enemyState.searching) { if (HandController.S.isCurrentlyKnocking()) { soundLocation = MovementController.player.transform.position; // Check distance between self and sound location if (Vector3.Magnitude(soundLocation - body.transform.position) <= 5f) { // If the player made a sound withing 5 meters of enemy // then make enemy alerted Debug.DrawLine(body.transform.position, soundLocation, Color.green, 1f); // Stop voice overlap if (!voiceSource.isPlaying) { playVoice(voice.enemyNoiseAlert); } punctuation.GetComponent <EnemyPunctuation> ().displayIcon(puncType.alert); agn.destination = soundLocation; curEnemyState = enemyState.investigating; } else { Debug.DrawLine(body.transform.position, soundLocation, Color.red, 1f); } } } }
private void Start() { myState = enemyState.patrol; player = GameObject.FindGameObjectWithTag("Player"); facingRight = true; rb = GetComponent <Rigidbody2D>(); }
void changeState(enemyState newState) { currentEnemyState = newState; switch (newState) { case enemyState.PARADO: velocidade = 0; StartCoroutine("idle"); break; case enemyState.PATRULHA: velocidade = velocidadeBase; break; case enemyState.ALERTA: velocidade = 0; alert.SetActive(true); break; case enemyState.ATACK: animator.SetTrigger("atack"); break; case enemyState.RECUAR: flip(); velocidade = velocidadeBase * 2; // modificar para distância ao invés de velocidade de movimento StartCoroutine("recuar"); break; } }
void Start() { currentAlarmState = enemyState.NotAlarmed; currentMovementState = enemyState.Patrolling; currentCombatState = enemyState.Ready; currentHealth = maxiumunHealth; }
private void moute() { if (!hasTarget) { return; } if (stopMoving) { return; } Vector3 movement = Vector3.zero; navi.SetDestination(target.position); Vector3 nextstep = navi.nextPosition; movement = nextstep - transform.position; movement.y = 0; float dist = movement.magnitude; if (navi.velocity.sqrMagnitude < 0.5) { _enemyState = enemyState.idle; } else { movement = movement.normalized * speed; _enemyState = enemyState.move; } //float step = speed * Time.deltaTime; //transform.position = Vector3.MoveTowards(transform.position, target.position, step); }
void Update() { switch (_enemyState) { case enemyState.idle: break; case enemyState.move: moute(); break; case enemyState.getBack: torna(); break; case enemyState.attack: break; case enemyState.die: break; default: _enemyState = enemyState.idle; break; } }
//NEW public void chasing() { float distance = Vector3.Distance(game.chosen.position, position); if (chasingPlayer) { if (animationPlayer.CurrentClip.Name != "Idle") { animationPlayer.StartClip(skinningData.AnimationClips["Idle"]); } else if (animationPlayer.CurrentClip.Name != "Fire") { animationPlayer.StartClip(skinningData.AnimationClips["Fire"]); } Vector3 temp = 2 * Vector3.Normalize(game.chosen.position - position); temp.Y = 0; temp.Z = 0; if (temp.X > 0) { rotationY = 0; } else if (temp.X < 0) { rotationY = MathHelper.ToRadians(180); } position += temp; } if (distance > chaseThreshold) { chasingPlayer = false; state = enemyState.PATROL; } }
//USE THIS INSTEAD OF HARD TRANSITIONING INTO STATES. THIS LETS YOU CONSISTENTLY DO COOL SHIT WHEN YOU TRANSITION //if i want to elaborate on this further i could have a second switch statement within each case with a stateFrom, so i can do like, a whew sound when going from alerted to idle but a ...huh sound from suspicious to idle //lots of work tho void transitionState(enemyState stateTo) { currentState = stateTo; switch (stateTo) { case enemyState.IDLE: break; case enemyState.SUSPICIOUS: pointOfInterest = playerLocator.position; nav.destination = pointOfInterest; reachedPointOfInterest = false; break; case enemyState.ALERTED: break; case enemyState.DEAD: nav.isStopped = true; anim.SetBool("Alive", false); enemyVisual.LookAt(playerChar); dropGun(); Instantiate(myBattery, transform.position, transform.rotation); break; } }
IEnumerator Shoot() { RaycastHit2D hit = Physics2D.Raycast(gun.position, gun.right * lengthRay); if (hit.collider != null) { if (hit.collider.gameObject.tag.Equals("Player")) { bulletReady = false; GameObject bulletTemp = Instantiate(bullet, gun.transform); bulletTemp.SetActive(true); bulletTemp.GetComponent <Rigidbody2D>().velocity = bulletSpeed * gun.transform.right; Destroy(bulletTemp, 6); yield return(new WaitForSeconds(1f)); bulletReady = true; } else { state = enemyState.PATROL; } } else { state = enemyState.PATROL; } }
public void doKnockback(float heldPower, int orientation) { float angleToUse = (orientation == 1 ? 135 : (orientation == 2 ? 90 : (orientation == 3 ? 45 : (orientation == 4 ? 180 : (orientation == 5 ? 0 : (orientation == 6 ? 225 : (orientation == 7 ? 270 : 315))))))); state = enemyState.FLYING; Vector3 temp = new Vector3(0, 0, 0); temp = transform.position - characterPos.transform.position; temp = Vector3.Normalize(temp); temp = new Vector3(temp.x * heldPower / knockbackResist, 0, temp.z * heldPower / knockbackResist); knockedDestination = temp + transform.position; direction = new Vector3(knockedDestination.x - transform.position.x, 0, knockedDestination.z - transform.position.z); direction = Vector3.Normalize(direction); knockbackSpeedFraction = Vector3.Distance(knockedDestination, transform.position) / knockbackSpeed; gameObject.GetComponent <Rigidbody>().velocity = direction * knockbackSpeedFraction; takeDmg(Mathf.Sqrt(heldPower)); }
public bool Attack(BuildingData target) { //if (target.Cell.GetWorldPosition().x != -1 && target.Cell.GetWorldPosition().y != -1) //{ transform.DOLookAt(target.Cell.GetWorldPosition(), MovementSpeed, AxisConstraint.Y); //} currentState = enemyState.Attack; animationType = AnimationType.Attack; if (target && target.CurrentState != BuildingState.Destroyed) { target.BuildingLife -= _attack; target.GetParticlesEffect(); } else if (!target) { currentState = enemyState.Searching; return(false); } if (target.BuildingLife <= 0) { //if (target) //{ GameManager.I.buildingManager.GetBuildingView(target.UniqueID).destroyMe(); // } currentState = enemyState.Searching; return(false); } return(true); }
public virtual void StateAttack() { if (_animator != null && GetAnimation(_animatorBools[2]) == false) { SetAnimation(_animatorBools[2]); //StartCoroutine(CR_Attack()); } SmoothLookAt(_graphic, _player.position); if (_animator != null) { AnimatorStateInfo _animStateInfo = _animator.GetCurrentAnimatorStateInfo(0); if (_animStateInfo.IsTag("attack")) { if (_animStateInfo.normalizedTime > .45f && _animStateInfo.normalizedTime < .5f) { _attackController.Attack(); } if (_animStateInfo.normalizedTime >= 1) { _state = enemyState.wonder; } } } }
private void torna() { if (stopMoving) { return; } Vector3 movement = Vector3.zero; navi.SetDestination(startingPosition); Vector3 nextstep = navi.nextPosition; thisNextstep = nextstep; movement = nextstep - transform.position; movement.y = 0; float dist = movement.magnitude; if (navi.velocity.sqrMagnitude < 0.5) { _enemyState = enemyState.idle; } else { movement = movement.normalized * speed; _enemyState = enemyState.move; } }
void ChangeState(enemyState newState) { StopAllCoroutines(); // Encerra todas corrotinas desse slime state = newState; isAlert = false; print(state); switch (state) { case enemyState.IDLE: destination = transform.position; agent.destination = destination; agent.stoppingDistance = 0; StartCoroutine("IDLE"); break; case enemyState.ALERT: destination = transform.position; agent.destination = destination; agent.stoppingDistance = 0; StartCoroutine("ALERT"); break; case enemyState.FOLLOW: destination = _GameManager.player.position; agent.stoppingDistance = _GameManager.slimeDistanceToAttack; agent.destination = destination; break; case enemyState.FURY: destination = _GameManager.player.position; agent.stoppingDistance = _GameManager.slimeDistanceToAttack; agent.destination = destination; agent.speed *= 2; isAlert = true; break; case enemyState.PATROL: idWayPoint = Random.Range(0, _GameManager.slimesWayPoints.Length); destination = _GameManager.slimesWayPoints[idWayPoint].position; agent.destination = destination; agent.stoppingDistance = 0; StartCoroutine("PATROL"); break; } }
private void OnEnable() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <GameObject>(); PlayerSkillController = GameObject.FindGameObjectWithTag("Player").GetComponent <SkillController>(); currentState = enemyState.IDLE; dropedItem = false; t = 0; }
void Start() { _player = GameObject.FindGameObjectWithTag("Player"); enemyAgent = GetComponent <NavMeshAgent>(); currentAlarmState = enemyState.NotAlarmed; currentMovementState = enemyState.Stationary; }
private IEnumerator AttackCooldownCounter(float cooldown) { yield return(new WaitForSeconds(cooldown)); currentState = enemyState.CHASING; enemyRb.velocity = Vector3.zero; enemyRb.rotation = 0; }
IEnumerator attack() //Функция атаки { state = enemyState.ATTACKING; enemyAudio.clip = attacking; enemyAudio.Play(); yield return(attackRepeatTime); targetStats.takingDamage(damage); }
void chase() //Функция пресследования { state = enemyState.CHASING; moveDirection = transform.forward; moveDirection *= movementSpeed; moveDirection.y -= gravity * Time.deltaTime; controller.Move(moveDirection * Time.deltaTime); }
void OnTriggerEnter(Collider triggerCol) { if (triggerCol.transform.tag.Equals("Player")) { Debug.Log("********** Persiguiendo al jugador"); currentState = enemyState.CHASING; StopCoroutine("UpdatePatrolPosition"); } }
public void setState(int state) { switch (state) { case 0: _enemyState = enemyState.idle;break; case 1: _enemyState = enemyState.move;break; case 2: _enemyState = enemyState.getBack;break; case 3: _enemyState = enemyState.attack;break; case 4: _enemyState = enemyState.die;break; default: _enemyState = enemyState.idle;break; } }
// Use this for initialization void Start () { directionsTurned = 0; pointDirectionSize = 0; body = gameObject.GetComponent<Rigidbody>(); agn = gameObject.GetComponent<NavMeshAgent>(); currentPoint = nextPoint; soundLocation = Vector3.zero; curEnemyState = enemyState.def; numTurns = 0; timeTilTurn = 0f; maxStamina = 7; curStamina = maxStamina; timeTilUp = 0f; }
private void torna() { if (stopMoving) return; Vector3 movement = Vector3.zero; navi.SetDestination(startingPosition); Vector3 nextstep = navi.nextPosition; thisNextstep = nextstep; movement = nextstep - transform.position; movement.y = 0; float dist = movement.magnitude; if( navi.velocity.sqrMagnitude < 0.5 ) { _enemyState = enemyState.idle; } else { movement = movement.normalized * speed; _enemyState = enemyState.move; } }
void evade() { if (incomingProjectile == null) return; if (Vector3.Distance(transform.position, player.position) > aggroRange) return; audioSource.Stop(); audioSource.PlayOneShot(isDodging); Vector3 relativePos = transform.InverseTransformPoint(incomingProjectile.position); //Incoming bullet is on the left, dodge right if (relativePos.x < 0) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("DodgeRight")) animator.SetTrigger("DodgeRight"); dodgingRight = true; dodgingLeft = false; dodgeDestination = transform.position + transform.right * dodgeDistance; } //Incoming bullet is on the right, dodge left else if (relativePos.x > 0) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("DodgeLeft")) animator.SetTrigger("DodgeLeft"); dodgingLeft = true; dodgingRight = false; dodgeDestination = transform.position + transform.right * -dodgeDistance; } //Incoming bullet is coming from straight ahead, dodge left(?) else { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("DodgeLeft")) animator.SetTrigger("DodgeLeft"); dodgingLeft = true; dodgingRight = false; dodgeDestination = transform.position + transform.right * -dodgeDistance; } state = enemyState.move; dodgeDurationRemaining = 0; }
void checkForIncomingShots(Transform shot) { if (state == enemyState.stunned) return; if (Vector3.Distance(player.transform.position, transform.position) > evadeDetectRadius) return; RaycastHit[] hitinfo; Ray ray = new Ray(shot.position, shot.forward); hitinfo = Physics.SphereCastAll(ray, shot.GetComponent<SphereCollider>().radius); foreach (RaycastHit hit in hitinfo) { if (hit.transform == transform) { state = enemyState.evade; incomingProjectile = shot; } } }
void stunned() { if(curStunTime <= 0) { pushed = false; curStunTime = stunTime; state = enemyState.move; } else { transform.Rotate(Vector3.up * turnSpeed * 100 * Time.deltaTime); } }
void stand() { myAnim.SetBool("move", false); if (!investigate && waypoints.Length <= 0 && Vector3.Distance(transform.position, startingPos) > 1) { eState = enemyState.patrol; } else { if (investigate) { agent.SetDestination(investigatePos); curPosition = transform.position; eState = enemyState.patrol; } else if (waypoints.Length > 0) { if (waypoints.Length - 1 < waypointID) { waypointID = 0; } agent.SetDestination(waypoints[waypointID].position); curPosition = transform.position; eState = enemyState.patrol; } else if (turningEnemy) { if (turnRight) { if (transform.rotation != startingRot) { transform.rotation = startingRot; } turnRight = false; actionpointsLeft = 0; } else { transform.Rotate(Vector3.up * -prefTurnAngle); turnRight = true; actionpointsLeft = 0; } actionpointsLeft--; } else { if (transform.rotation != startingRot) { transform.rotation = startingRot; } actionpointsLeft = 0; } } }
void charge() { if (!speedParticle.activeSelf) speedParticle.SetActive(true); if(curChargeTime <= 0) { curChargeTime = chargeTime; if (speedParticle.activeSelf) speedParticle.SetActive(false); state = enemyState.idle; } else if(Vector3.Distance(chargeStartPos, transform.position) < chargeDistance) { transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime); curChargeTime--; } else { curChargeTime = chargeTime; if (speedParticle.activeSelf) speedParticle.SetActive(false); state = enemyState.idle; } }
// float step = speed * Time.deltaTime; // Use this for initialization void Start () { currentPlayerState = playerState.normal; currentEnemyState = enemyState.follow; }
void fire() { if (!landingIndicator.isPlaying) landingIndicator.Play(); landingIndicator.transform.position = playerPos; if(Vector3.Distance(transform.position, orb.position) < 50) { orb.Translate(Vector3.forward * orbFlySpeed * Time.deltaTime); } else { orb.transform.localPosition = new Vector3(0,0,1); orb.transform.localScale = new Vector3(0.2F, 0.2F, 0.2F); Instantiate(orbPrefab, playerPos + (Vector3.up * 40), Quaternion.identity); orbReady = false; state = enemyState.idle; } }
void regenerateOrb() { if(orb.localScale != desiredOrbScale) { orb.localScale = Vector3.Lerp(orb.localScale, desiredOrbScale, regenerationSpeed); leafX1.localRotation = Quaternion.Lerp(leafX1.localRotation, Quaternion.Euler(new Vector3(35, 0, 180)), regenerationSpeed); leafX2.localRotation = Quaternion.Lerp(leafX2.localRotation, Quaternion.Euler(new Vector3(-35, 0, 0)), regenerationSpeed); leafY1.localRotation = Quaternion.Lerp(leafY1.localRotation, Quaternion.Euler(new Vector3(0, 35, 270)), regenerationSpeed); leafY2.localRotation = Quaternion.Lerp(leafY2.localRotation, Quaternion.Euler(new Vector3(0, -35, 90)), regenerationSpeed); leafs.localRotation = Quaternion.Lerp(leafs.localRotation, Quaternion.identity, regenerationSpeed); } else { leafX1.localRotation = Quaternion.Euler(new Vector3(35, 0, 180)); leafX2.localRotation = Quaternion.Euler(new Vector3(-35, 0, 0)); leafY1.localRotation = Quaternion.Euler(new Vector3(0, 35, 270)); leafY2.localRotation = Quaternion.Euler(new Vector3(0, -35, 90)); leafs.localRotation = Quaternion.identity; orbReady = true; toFire = false; state = enemyState.idle; } }
public void Kill() { m_state = enemyState.Dead; float distance = (Camera.position - m_position).Length(); distance = ( 250.0f / distance ); distance = distance > 1.0f ? 1.0f : distance; m_die_sound.Play(distance * 0.5f, 0.0f, 0.0f); }
// Update is called once per frame void Update () { agn.enabled = true; // print (this.name + " init directionsTurned: " + (directionsTurned)); // Knockout State if (curEnemyState == enemyState.knockout) { if (timeTilUp < downTime) { // Make them look like they fell over this.transform.localScale = new Vector3 (0.75f, 0.375f, 1.5f); radarIcon.transform.localScale = new Vector3 (0.067f, 0.1333f, 0.6667f); if (curStamina <= 0) punctuation.GetComponent<EnemyPunctuation> ().displayIcon (puncType.starKnockout); // Turn of sight cone sightConeRenderer.enabled = false; agn.Stop (); timeTilUp += Time.deltaTime; } else { // Stand back up, loser this.transform.localScale = new Vector3 (0.75f, 1.5f, 0.375f); radarIcon.transform.localScale = new Vector3 (0.2667f, 0.1333f, 0.6667f); timeTilUp = 0f; agn.Resume (); if (curStamina <= 0) curStamina = 7; // Restore stamina sightConeRenderer.enabled = true; curEnemyState = enemyState.searching; } } else if (curStamina <= 0) { playVoice (voice.enemyFlip); curEnemyState = enemyState.knockout; punctuation.GetComponent<EnemyPunctuation> ().displayIcon (puncType.starKnockout); print ("IM DOWN"); } // DamagedState else if (curEnemyState == enemyState.stun) { if (timeTilNoStun < stunTime) { agn.Stop (); timeTilNoStun += Time.deltaTime; } else { agn.Resume(); timeTilNoStun = 0f; curEnemyState = enemyState.searching; } } // Knockout takes priority lol sorry for the bad code else { // Default State if (curEnemyState == enemyState.def) { sightConeRenderer.sprite = radarSprites [(int)radar.sight]; // If player "touches" enemy, make enemy start searching if (Vector3.Magnitude (transform.position - MovementController.player.transform.position) <= 0.5f) curEnemyState = enemyState.searching; // Once the point changes... if (currentPoint != nextPoint) { // Start countdown timer timeTilMove = pauseTime; currentPoint = nextPoint; } // Count down until time to move if (timeTilMove > 0) { if (staysSamePoint) body.transform.rotation = Quaternion.LookRotation (Vector3.Slerp (body.transform.forward, pointDirection[directionsTurned - 1], rotationSpeed)); else body.transform.rotation = Quaternion.LookRotation (Vector3.Slerp (body.transform.forward, pointDirection[directionsTurned], rotationSpeed)); timeTilMove -= Time.deltaTime; } // Once timer runs down... else { // If it hasn't gone through all the turns if (directionsTurned < (pointDirectionSize - 1) || (staysSamePoint && directionsTurned < pointDirectionSize)) { timeTilMove = pauseTime; directionsTurned += 1; } else { directionsTurned = 0; Vector3 targetDir = nextPoint.transform.position - transform.position; if (Vector3.Angle (body.transform.forward, targetDir) > 45f) { body.transform.rotation = Quaternion.LookRotation (Vector3.Slerp (body.transform.forward, targetDir, rotationSpeed)); } else { agn.destination = nextPoint.transform.position; } } } } // Alerted State else if (curEnemyState == enemyState.investigating) { // Change sightcone red sightConeRenderer.sprite = radarSprites [(int)radar.alert]; // Once you reach the sound location (with some bounce room) if (Vector3.Magnitude (transform.position - agn.destination) <= 0.8f) { // Go into search state curEnemyState = enemyState.searching; } } // Searching State else if (curEnemyState == enemyState.searching) { // Stop moving agn.enabled = false; // Change sightcone red sightConeRenderer.sprite = radarSprites [(int)radar.alert]; if (numTurns <= 3) { if (timeTilTurn < alertLookTime) timeTilTurn += Time.deltaTime; else { print ("Rotating..."); if (numTurns == 0) { turnDirection = body.transform.right; playVoice (voice.confused); punctuation.GetComponent<EnemyPunctuation>().displayIcon(puncType.question); } if (numTurns == 1) turnDirection = body.transform.forward * -1; if (numTurns == 2) { turnDirection = body.transform.right; sightConeRenderer.sprite = radarSprites [(int)radar.sight]; } numTurns++; timeTilTurn = 0f; } body.transform.rotation = Quaternion.LookRotation (Vector3.Slerp (body.transform.forward, turnDirection, rotationSpeed)); } else { numTurns = 0; curEnemyState = enemyState.def; currentPoint = nextPoint; } } // UNIVERSAL FOR ALL STATES // Make player invincible if (!MovementController.player.bigBossMode) { // If player enters sight cone, game over EnemySight (); } // If player makes noise, investigate EnemyHearing (); } }
public override void update(Visualisation vis, GameTime time, GraphicsDevice graphics, GameState gamestate) { switch (m_state) { case enemyState.Standing : break; case enemyState.Walking: if (m_way_points.Count > 1) { m_position += (m_move_distance * (0.08f * GamePlay.difficulty.GetHashCode()) ); float length = (m_way_points[m_active_way_point] - m_position).Length(); m_rotation.Y = m_destination_angle; if (length <= 1.0f) { m_active_way_point++; if (m_active_way_point >= m_way_points.Count) m_active_way_point = 0; m_move_distance = m_way_points[m_active_way_point] - m_position; m_move_distance.Normalize(); m_rot_offset = Vector3.Dot(m_move_distance, Vector3.Forward) < 0 ? 0.0f : (float)Math.PI; m_destination_angle = (float)Math.Atan((m_position.X - m_way_points[m_active_way_point].X) / (m_position.Z - m_way_points[m_active_way_point].Z)) + m_rot_offset; } } else { m_state = enemyState.Standing; } break; case enemyState.Dead: if (m_rotation.X >= -MathHelper.PiOver2) { m_rotation.X -= 0.05f; m_position.Y += 0.01f; } break; } base.update(vis, time, graphics, gamestate); }
void Start () { // enemyState currentState; currentState = enemyState.follow; }
void attack() { lookAt(player); if (Vector3.Distance(transform.position, player.position) > maxAttackDistance || Vector3.Distance(transform.position, player.position) < minAttackDistance) { state = enemyState.move; } if (barrelEnd != null && shotPrefab != null) { Vector3 fixedPos = new Vector3(player.position.x, player.position.y+1.5f, player.position.z); barrelEnd.LookAt(fixedPos); if (curGunCooldown <= 0) { GameObject shotGo = Instantiate(shotPrefab, barrelEnd.position, barrelEnd.rotation) as GameObject; Shot shot = shotGo.GetComponent<Shot>(); shot.Initialize(GameData.shotMoveSpeedTable[(int)team], GameData.shotDamageTable[(int)GameData.EnemyType.Navi], team, GameData.ShotType.Normal, transform); audioSource.Stop(); audioSource.PlayOneShot(onShoot); curGunCooldown = gunCooldown; } } }
void playTurn() { if(actionpointsLeft <= 0) { myAnim.SetBool("move", false); actionpointsLeft = maxActionPoints; agent.SetDestination(transform.position); eState = enemyState.stand; base.state = Enemy.enemyState.idle; } else { if (actionpointsLeft == maxActionPoints) { if (Vector3.Distance(transform.position, player.transform.position) < 50 && eState == enemyState.patrol) { AudioManager.PlayCraberino(); } } switch (eState) { case enemyState.stand: stand(); break; case enemyState.patrol: patrol(); break; default: break; } } }
void readyUp() { if (speedParticle.activeSelf) speedParticle.SetActive(false); lookAt(player); //animate here rotatingPoint.RotateAround(transform.forward, Mathf.Lerp(currentRotationSpeed, maxRotateSpeed, Mathf.Abs((((100 / (float)readyTime) * curReadyTime)) / 100 - 1))); if(curReadyTime <= 0) { curReadyTime = readyTime; chargeStartPos = transform.position; state = enemyState.charge; audioSource.Stop(); audioSource.PlayOneShot(onCharge); } }
void Update() { switch (_enemyState) { case enemyState.idle: break; case enemyState.move: moute(); break; case enemyState.getBack: torna (); break; case enemyState.attack: break; case enemyState.die: break; default: _enemyState = enemyState.idle; break; } }
// Update is called once per frame protected override void Update() { base.Update(); switch (state) { case enemyState.idle: idle(); break; case enemyState.move: move(); break; case enemyState.attack: attack(); break; case enemyState.stunned: stunned(); break; case enemyState.die: Die(); break; default: break; } if (attacking && state != enemyState.stunned) attack(); if (state != enemyState.die && state != enemyState.stunned) { if(pushed) { state = enemyState.stunned; } } if(curHealth <= 0) { state = enemyState.die; } }
// Update is called once per frame protected override void Update() { base.Update(); switch(state) { case enemyState.idle: idle(); break; case enemyState.readyUp: readyUp(); break; case enemyState.charge: charge(); break; case enemyState.die: Die(); break; } if (curHealth <= 0) { state = enemyState.die; } }
void idle() { if (Vector3.Distance(transform.position, player.position) <= detectRadius) { state = enemyState.move; } }
void idle() { if(!orbReady) { state = enemyState.regenerateOrb; audioSource.Stop(); audioSource.PlayOneShot(isRegenerating); } if (orbReady) { if (landingIndicator.isPlaying) landingIndicator.Stop(); } if(orbReady && toFire) { toFire = false; state = enemyState.chargeUp; audioSource.Stop(); audioSource.PlayOneShot(isCharging); } }
// KnockOut void OnTriggerEnter(Collider other) { // print("Triggered: " + other.gameObject.name); if (curEnemyState != enemyState.knockout) { // If player walks into enemy if (other.name == "Snake") { curEnemyState = enemyState.searching; } // If enemy is grabbed if (HandController.S.isGrabbing) { if (other.tag == "Hand") { curStamina -= 5; playVoice (voice.enemyFlip); curEnemyState = enemyState.knockout; HandController.S.curCooldown += .25f; } } // If player is trying to fight enemy if (HandController.S.isFighting) { // If enemy is punched if (other.tag == "Hand" || other.tag == "Leg") { playVoice (voice.enemyPunched); curEnemyState = enemyState.stun; timeTilNoStun = 0f; } if (other.tag == "Hand") curStamina -= 1; if (other.tag == "Leg") { curEnemyState = enemyState.knockout; playVoice (voice.enemyFlip); curStamina -= 2; } } } }
void chargeUp() { if(curChargeDuration <= 0) { curChargeDuration = chargeDuration; playerPos = player.position; leafX1.localRotation = Quaternion.Euler(new Vector3(0, 0, 180)); leafX2.localRotation = Quaternion.Euler(new Vector3(0, 0, 0)); leafY1.localRotation = Quaternion.Euler(new Vector3(0, 0, 270)); leafY2.localRotation = Quaternion.Euler(new Vector3(0, 0, 90)); state = enemyState.fire; audioSource.Stop(); audioSource.PlayOneShot(onShoot); } else { leafs.Rotate(Vector3.forward * curChargeSpeed * Time.deltaTime); } }
void EnemyHearing() { // Check to see if player is knocking only if not searching if (curEnemyState != enemyState.searching) { if (HandController.S.isCurrentlyKnocking ()) { soundLocation = MovementController.player.transform.position; // Check distance between self and sound location if (Vector3.Magnitude (soundLocation - body.transform.position) <= 5f) { // If the player made a sound withing 5 meters of enemy // then make enemy alerted Debug.DrawLine (body.transform.position, soundLocation, Color.green, 1f); // Stop voice overlap if (!voiceSource.isPlaying) playVoice (voice.enemyNoiseAlert); punctuation.GetComponent<EnemyPunctuation> ().displayIcon (puncType.alert); agn.destination = soundLocation; curEnemyState = enemyState.investigating; } else { Debug.DrawLine (body.transform.position, soundLocation, Color.red, 1f); } } } }
void patrol() { myAnim.SetBool("move", true); if(Vector3.Distance(transform.position, curPosition) >= actionPointLength) { actionpointsLeft--; curPosition = transform.position; } if (agent.remainingDistance <= 0.01F) { if (!investigate && waypoints.Length > 0) { waypointID++; actionpointsLeft = 0; } else { if(investigate) { actionpointsLeft = 0; } investigate = false; AudioManager.HandleBackgroundMusic(); foreach(FOV fov in fovs) { fov.alert = FOV.alertState.normal; } agent.SetDestination(startingPos); } eState = enemyState.stand; } }
// Update is called once per frame protected override void Update() { base.Update(); switch (state) { case enemyState.idle: animator.SetBool("Forward", false); animator.SetBool("Backoff", false); idle(); break; case enemyState.move: move(); break; case enemyState.attack: animator.SetBool("Forward", false); animator.SetBool("Backoff", false); attack(); break; case enemyState.evade: animator.SetBool("Forward", false); animator.SetBool("Backoff", false); evade(); break; case enemyState.stunned: animator.SetBool("Forward", false); animator.SetBool("Backoff", false); stunned(); break; case enemyState.die: animator.SetBool("Forward", false); animator.SetBool("Backoff", false); Die(); break; default: break; } if (attacking && state != enemyState.stunned) attack(); if (state != enemyState.die && state != enemyState.stunned) { if(pushed) { state = enemyState.stunned; } } if(curHealth <= 0) { state = enemyState.die; } if(state == enemyState.stunned) { if(gameObject.layer == LayerMask.NameToLayer("Invincible")) { gameObject.layer = LayerMask.NameToLayer("Default"); } } else { if (gameObject.layer != LayerMask.NameToLayer("Invincible")) { gameObject.layer = LayerMask.NameToLayer("Invincible"); } } if (dodgingRight) { if (dodgeDurationRemaining >= 1) { dodgeDurationRemaining = 0; dodgingRight = false; } else { transform.position = Vector3.Lerp(transform.position, dodgeDestination, dodgeDurationRemaining); dodgeDurationRemaining += Time.deltaTime * dodgeSpeed; } } else if (dodgingLeft) { if (dodgeDurationRemaining >= 1) { dodgeDurationRemaining = 0; dodgingLeft = false; } else { transform.position = Vector3.Lerp(transform.position, dodgeDestination, dodgeDurationRemaining); dodgeDurationRemaining += Time.deltaTime * dodgeSpeed; } } }