//------------------------------------------ public IEnumerator AIPatrol() { //Loop while patrolling while (currentstate == ENEMY_STATE.PATROL) { //Set strict search ThisLineSight.Sensitity = LineSight.SightSensitivity.STRICT; //Chase to patrol position ThisAgent.Resume(); ThisAgent.SetDestination(PatrolDestination.position); //Wait until path is computed while (ThisAgent.pathPending) { yield return(null); } //If we can see the target then start chasing if (ThisLineSight.CanSeeTarget) { ThisAgent.Stop(); CurrentState = ENEMY_STATE.CHASE; yield break; } //Wait until next frame yield return(null); } }
//몬스터의 상태값에 따라 적절한 동작을 수행하는 함수 IEnumerator MonsterAction() { while (!isDie) { switch (monsterState) { //idle 상태 case MonsterState.idle: //추격중지 animator.SetBool("IsTrace", false); nvAgent.Stop(); break; case MonsterState.trace: nvAgent.destination = playerTr.position; nvAgent.Resume(); animator.SetBool("IsAttack", false); animator.SetBool("IsTrace", true); break; case MonsterState.attack: nvAgent.Stop(); animator.SetBool("IsAttack", true); break; } yield return(null); } }
private void SetState(MonsterState state) { CancelAllTimers(kStateTimerTag); m_state = state; m_navMeshAgent.Stop(); }
IEnumerator BadGuyAction() { while (!isDie) { switch (badguyState) { case BadGuyState.idle: nvAgent.Stop(); animator.SetBool("IsRun", false); break; case BadGuyState.run: nvAgent.destination = PlayerTr.position; nvAgent.Resume(); animator.SetBool("IsAttack", false); animator.SetBool("IsRun", true); break; case BadGuyState.attack: nvAgent.Stop(); animator.SetBool("IsAttack", true); break; } yield return(null); } }
//------------------------------------ public IEnumerator StateChase() { ++ActiveEnemies; //Run chase animation ThisAnimator.SetInteger("AnimState", (int)ActiveState); //Set destination ThisAgent.SetDestination(PlayerTransform.position); //Wait until path is calculated while (!ThisAgent.hasPath) { yield return(null); } //While in idle state while (ActiveState == AISTATE.CHASE) { if (ThisAgent.remainingDistance <= ThisAgent.stoppingDistance) { ThisAgent.Stop(); yield return(null); ActiveState = AISTATE.ATTACK; yield break; } yield return(null); } }
void SwitchDead() { ani.SetBool("isDead", true); agent.Stop(); //停止寻路 this.GetComponent <CapsuleCollider> ().enabled = false; //关闭碰撞器 PlaySoundDead(deadAC); }
IEnumerator PrincessAction() { while (!isDie) { switch (princessState) { case PrincessState.idle: nvAgent.Stop(); animator.SetBool("IsRun", false); break; case PrincessState.run: // nvAgent.destination = PrinceTr.position; nvAgent.Resume(); animator.SetBool("IsJump", false); animator.SetBool("IsRun", true); break; case PrincessState.jump: nvAgent.Stop(); animator.SetBool("IsJump", true); break; } yield return(null); } }
private void SetIdleMode() { if (navAgent.isOnNavMesh) { navAgent.Stop(); } animator.SetFloat("Speed", 0f); animator.SetFloat("Direction", 0); }
public void AddBuff(int type, float time) { Debug.Log("addbuff " + type); if (buffsByType.ContainsKey(type)) { buffsByType [type].time = time; } else { Buff b = new Buff() { type = type, time = time }; buffsByType.Add(type, b); buffs.Add(b); DoBuffs(); } switch (type) { case BuffIndex.blind: { canMove = false; nma.Stop(); if (target != null) { Transform t = target; target = null; MoveTo(t); } break; } case BuffIndex.stun: { canMove = false; nma.Stop(); if (target != null) { Transform t = target; target = null; MoveTo(t); } break; } case BuffIndex.catching: { //catching anim break; } } }
void Update() { if (checkForCheater == 1 && agent.remainingDistance < 2f && paused == false && fakeCall == false) { if (!source.isPlaying) { source.PlayOneShot(alert); } } if (agent.remainingDistance < 0.1f) { GotoNextPoint(); } if (student.isCheating == true) { ctch.cheating = true; } else if (student.isCheating == false) { ctch.cheating = false; } if (busted == true) { //Game Over gameMan.isGameOver = true; //Kağıttaki Değişiklikler scoreInfo.text = "BUSTED"; //Busted Animasyonu Oynatılacak } if (timeUp.isTimeOver == true) { //Time is Up Animasyonu Oynatılacak } if (paused == true) { agent.Stop(); } else if (paused == false && busted == false) { agent.Resume(); } //FakeCall if (fakeCall == true) { agent.Stop(); } else if (fakeCall == false && busted == false && paused == false) { agent.Resume(); } FootSteps(); }
public void SetTargetPos(Vector3 pos) { // Debug.LogError("SetTargetPos " + pos); if (navMA != null) { float dis = Mathf.Abs(Vector2.Distance(new Vector2(pos.x, pos.z), new Vector2(transform.localPosition.x, transform.localPosition.z))); if (Mathf.Abs(Vector2.Distance(new Vector2(pos.x, pos.z), new Vector2(transform.localPosition.x, transform.localPosition.z))) <= 0.2f) { if (navMA.enabled) { navMA.Stop(); } PlayPrepare(); // Debug.LogError("dis is " + dis); return; } //if(posL.Count != 0&&Mathf.Abs( Vector3.Distance(pos,posL[0]))<0.2f) //{ // navMA.Stop(); // return; //} //posL.Clear(); //posL.Add( pos ); //if (!navMA.gameObject.activeSelf) //{ // navMA.gameObject.SetActive(true); //} sererpos.x = pos.x; sererpos.y = pos.y; sererpos.z = pos.z; if (!navMA.enabled) { navMA.enabled = true; } //if (!navMA.gameObject.activeSelf) //{ // navMA.gameObject.SetActive(true); //} //navMA.enabled = true; if (navMA != null && navMA.enabled) { navMA.Stop(); navMA.ResetPath(); navMA.Resume(); navMA.stoppingDistance = 0.1f; navMA.SetDestination(sererpos); // Debug.LogError("sererpos is " + sererpos); } } }
void Update() { if (isDie && !dieprocessed) { dieprocessed = true; agent.Stop(); animator.enabled = false; Destroy(agent); Destroy(gameObject, 10); } if (HitOnNextFrame) { HitOnNextFrame = false; ragdoll.Hit(hitposition, hitforward, gobject.HP <= 0); } if (agenttarget == null) { agent.speed = 0; animator.SetBool("isWalk", false); return; } var collist = Physics.OverlapSphere(transform.position + transform.TransformDirection(new Vector3(0, 0, 0.75f)), 0.5f); for (int i = 0; i < collist.Length; i++) { if (collist[i].gameObject.Equals(agenttarget) && agent) { animator.SetTrigger("Attack"); agent.Stop(); } } if (agent && agent.isActiveAndEnabled) { agent.speed = agentspeed; agent.SetDestination(new Vector3(agenttarget.transform.position.x, transform.position.y, agenttarget.transform.position.z)); if (agent.velocity.magnitude > 0.05f) { animator.SetBool("isWalk", true); } else { animator.SetBool("isWalk", false); } } }
void FixedUpdate() { if (health.IsDead() == false) // behavior if the character is alive { ChooseTarget(player1, player2); // which player to attack ApproachAndAttack(); // follow and player attack animation Animate(); // keep updating animation controller } else if (health.IsDead()) // when it is dead { agent.Stop(); // stop following player Animate(); // keep updating animation controller } }
/* * Determines state of drone * In turret mode, stops moving, clears path, looks at player and checks to see if it can still see him * In search mode, tries to find the player based on some initial position, checks to see if it can see the player */ void Update() { DRONE_FACING = transform.TransformDirection(Vector3.forward); if (turret) { drone_agent.Stop(true); drone_agent.ResetPath(); transform.LookAt(playerRef.transform.position); turret = vision(); } else { drone_agent.Resume(); if (startSearch) { playerPosition = playerRef.transform.position; drone_agent.SetDestination(playerPosition); startSearch = false; } else if (withinRange(playerPosition, SEARCH_RADIUS)) { startSearch = true; } else if (drone_agent.velocity.Equals(new Vector3(0, 0, 0))) { startSearch = true; } turret = vision(); } }
IEnumerator MonsterAction() { while (!isDie) { switch (monsterState) { case MonsterState.idle: nvAgent.Stop(); animator.SetBool("isIdle", true); animator.SetBool("isRun", false); break; case MonsterState.trace: nvAgent.destination = PlayerTr.position; nvAgent.Resume(); animator.SetBool("isHit", false); animator.SetBool("isRun", true); break; case MonsterState.hit: nvAgent.destination = PlayerTr.position; nvAgent.Resume(); animator.SetBool("isHit", true); animator.SetBool("isRun", true); break; } yield return(null); } }
void Update() { if (!enemySonar.playerDetected) { WaypointWalk(); } //Wenn ich und der Spieler gesund sind, ich nicht geschockt bin und //ich angriffbereit bin else if (enemyHealth.health > 0 && playerHealth.health > 0 && //!enemySonar.obstacleDetected && !enemyHealth.isShocked && readyToHit) { agent.speed = attackingSpeed; agent.acceleration = 2; agent.SetDestination(player.transform.position); //Unity 5 -B agent.Resume(); //Pfadsuche weiter machen (falls gestoppt wurde) //Unity 5 -E } else { //Unity 5 -B //agent.Stop (true); agent.Stop(); //Pfadsuche stoppen agent.velocity = new Vector3(0, 0, 0); //Sofort anhalten //Unity 5 -E } }
void Update() { navMesh.destination = Player.transform.position; float Distance = Vector3.Distance(Player.transform.position, transform.position); if (Distance <= 6.0f) { navMesh.Stop(); if (isAttack == false) { ani.SetBool("Idle", true); StartCoroutine(Attack()); } } else { ani.SetBool("Idle", false); navMesh.Resume(); } }
void MoveAndShot() { if (targetedEnemy == null) { return; } navAgent.destination = targetedEnemy.position; if (navAgent.remainingDistance >= shootDistance) { navAgent.Resume(); walking = true; } if (navAgent.remainingDistance <= shootDistance) { transform.LookAt(targetedEnemy); if (Time.time > nextFire) { nextFire = Time.time + timeBetweenShots; Fire(); } navAgent.Stop(); walking = false; } }
void GoToFire() { nav.Stop(); state = FIRE; anim.SetTrigger("Fire"); timer = 0f; }
// Update is called once per frame void Update() { nav.SetDestination(Destination.transform.position); if (destinationInRange == true) { nav.Stop(); anim.SetFloat("Speed_f", 0); if (chosenmove == 2) { anim.SetBool("Lean_b", true); } if (chosenmove == 3) { anim.SetBool("Smoking_b", true); } if (chosenmove == 6) { anim.SetBool("Sit_b", true); } if (chosenmove == 4) { anim.SetBool("Checktime_b", true); } } else if (destinationInRange == false) { nav.SetDestination(Destination.transform.position); anim.SetFloat("Speed_f", 10); } else { anim.SetFloat("Speed_f", 10); } }
static void VerificaVida(GameObject atacante, CreatureManager doAtacado, Animator a) { if (doAtacado.MeuCriatureBase.CaracCriature.meusAtributos.PV.Corrente <= 0) { a.SetBool("cair", true); UnityEngine.AI.NavMeshAgent nav = a.GetComponent <UnityEngine.AI.NavMeshAgent>(); if (nav.enabled) { nav.Stop();// nav.isStopped = true; } /* doAtacado.MudaParaDerrotado(); * * if (!doAtacado.gerenteCri) * { * AplicaSelvagemDerrotado aSD = doAtacado.gameObject.AddComponent<AplicaSelvagemDerrotado>(); * aSD.oDerrotado = doAtacado; * aSD.oQDerrotou = atacante.GetComponent<GerenciadorDeCriature>(); * * } * else * { * //Morte de um criature selvagem * } */ } }
void SetNavVariables() { remainingDistance = navAgent.remainingDistance; if (trackingInfo.playerDetected) { if (remainingDistance > 2) { navAgent.Resume(); navAgent.speed = 4.5f; } else { navAgent.Stop(); navAgent.updateRotation = true; transform.LookAt(player); navAgent.speed = 2.0f; } } else { navAgent.stoppingDistance = 0; } }
//die// public void death() { anim.SetTrigger("dead"); anim.speed = 1f; alive = false; nav.Stop(); }
void DeathState() { animator.SetBool("isDeath", true); nav.Stop(); gameObject.GetComponent <Monster_Skeleton>().enabled = false; gameObject.GetComponent <EventTrigger>().enabled = false; }
private void MoveAndShoot() { if (targetedEnemy == null) { return; } navMeshAgent.destination = targetedEnemy.position; if (navMeshAgent.remainingDistance >= shootDistance && !_isRotating) { StartCoroutine("rotateToTarget", targetedEnemy.position); //navMeshAgent.Resume(); //walking = true; } if (navMeshAgent.remainingDistance <= shootDistance && navMeshAgent.pathPending == false) { Vector3 dirToShoot = targetedEnemy.transform.position - transform.position; if (Time.time > nextFire) { nextFire = Time.time + shootRate; targetedEnemy.GetComponent <lanternMain>().activate(); anim.SetBool("startWalking", false); anim.SetBool("startInteracting", true); } navMeshAgent.Stop(); walking = false; enemyClicked = false; } }
protected override void FixedUpdate() { base.FixedUpdate(); if (isAlive) { // go to closest target target = GetTarget(); if (target != null) { nav.SetDestination(target.position); float distFromTarget = Vector3.Distance(transform.position, target.transform.position); if (distFromTarget <= attackDist) { Attack(); } } } else { nav.velocity = Vector3.zero; nav.Stop(); } // Set anim vars anim.SetFloat("Speed", currentSpeed); anim.SetFloat("Speed01", currentSpeed / nav.speed); }
//loops over path positions, sets the //current target destination of this agent IEnumerator GoToDestination() { //path index int i = 0; //iterate over all positions while (i < path.Length) { //teleport to the current position agent.Warp(path[i]); i++; //walk to the next position agent.SetDestination(path[i]); while (agent.pathPending) { yield return(null); } //wait until we reached this position float remain = agent.remainingDistance; while (remain == Mathf.Infinity || remain - agent.stoppingDistance > float.Epsilon || agent.pathStatus != UnityEngine.AI.NavMeshPathStatus.PathComplete) { remain = agent.remainingDistance; yield return(null); } //increase counter i++; } //agent reached the final destination agent.Stop(true); }
//NavMeshAgentの動作 IEnumerator MoveNormalSpeed(UnityEngine.AI.NavMeshAgent agent) { if (agent.enabled) { agent.autoTraverseOffMeshLink = false; // OffMeshLinkによる移動を禁止 while (true) { // OffmeshLinkに乗るまで普通に移動 yield return(new WaitWhile(() => agent.isOnOffMeshLink == false)); // OffMeshLinkに乗ったので、NavmeshAgentによる移動を止めて、 // OffMeshLinkの終わりまでNavmeshAgent.speedと同じ速度で移動 agent.Stop(); yield return(new WaitWhile(() => { modelRoot.position = Vector3.MoveTowards( modelRoot.position, agent.currentOffMeshLinkData.endPos, agent.speed * Time.deltaTime); return Vector3.Distance(modelRoot.position, agent.currentOffMeshLinkData.endPos) > 0.1f; })); // NavmeshAgentを到達した事にして、Navmeshを再開 //agent.CompleteOffMeshLink(); //agent.Resume(); } } }
void UpdateMove() { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); if (JoyStickController.h != 0 || JoyStickController.v != 0) { h = JoyStickController.h; v = JoyStickController.v; } if (h != 0f || v != 0f) { Vector3 tempVector = new Vector3(h, 0f, v); tempVector.Normalize(); Vector3 relative = transform.InverseTransformPoint(transform.position + tempVector); float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg; transform.Rotate(Vector3.up * angle); m_NavAgent.velocity = Vector3.zero; //cc.Move(tempVector * m_Speed * Time.deltaTime); m_NavAgent.Move(tempVector * m_Speed * Time.deltaTime); if (!m_Animator.GetBool("Move")) { m_Animator.SetBool("Move", true); } } else { m_NavAgent.Stop(); if (m_Animator.GetBool("Move")) { m_Animator.SetBool("Move", false); } } }
// Update is called once per frame //play animation if velocity is 0, otherwise don't void Update() { animator.SetFloat("MoveSpeed", Vector3.Magnitude(nav.velocity) / nav.speed); //Debug.Log(Vector3.Magnitude(nav.velocity)); //Debug.Log("SHT"); if (move && !npcDialogue.running) { nav.Resume(); if (wander) { moveTowards = false; patrol = false; StartCoroutine(Wander()); } if (moveTowards) { patrol = false; wander = false; moveTo(curTarget); } if (patrol && !onPatrol) { wander = false; moveTowards = false; StartCoroutine(Patrol()); } } else { animator.SetFloat("MoveSpeed", 0f); nav.Stop(); } }