// OnIdleEnter is to be called when entering/starting the Idle State. void OnIdleEnter() { // For testing purposes i wanna use the stateNote.Text. The text above the Enemy's head stateNote.text = "Idle"; // When I enter the Idle State I wanna reset the NavMesh/Nav Agent path, so I don't have a preexisting path. agent.ResetPath(); }
IEnumerator UseQ() { Vector3 position = gameObject.transform.Find("Skill_Q_Point").transform.position; float Q_Anim_Time = 0; agent.speed = SPEED() * 1.5f; agent.SetDestination(position); while (!SkillQ.GetComponent <Active>().isActive) { // if (Vector3.Distance(position, gameObject.transform.position) <= 0 || Q_Anim_Time > (4 / agent.speed)) { if (agent.speed == (SPEED() * 1.5f)) { animator.SetBool("Skill_Q", false); Skill_Q_HitBox_Disable(); agent.speed = SPEED(); agent.ResetPath(); playerController.SetMoveable(true); } } else { Q_Anim_Time += Time.deltaTime; } yield return(new WaitForFixedUpdate()); } }
// Update is called once per frame void Update() { if (m_player.m_life <= 0) { return; } m_timer -= Time.deltaTime; AnimatorStateInfo stateInfo = m_ani.GetCurrentAnimatorStateInfo(0); if (stateInfo.fullPathHash == Animator.StringToHash("Base Layer.idle") && !m_ani.IsInTransition(0)) { m_ani.SetBool("idel", false); if (m_timer > 0) { return; } if (Vector3.Distance(m_transform.position, m_player.m_transform.position) < 1.5f) { m_agent.ResetPath(); m_ani.SetBool("attack", true); } else { m_timer = 1; m_agent.SetDestination(m_player.m_transform.position); m_ani.SetBool("run", true); } } if (stateInfo.fullPathHash == Animator.StringToHash("Base Layer.run") && !m_ani.IsInTransition(0)) { m_ani.SetBool("run", false); if (m_timer < 0) { m_agent.SetDestination(m_player.m_transform.position); m_timer = 1; } if (Vector3.Distance(m_transform.position, m_player.m_transform.position) < 1.5f) { m_agent.ResetPath(); m_ani.SetBool("attack", true); } } if (stateInfo.fullPathHash == Animator.StringToHash("Base Layer.attack") && !m_ani.IsInTransition(0)) { RotateTo(); m_ani.SetBool("attack", false); if (stateInfo.normalizedTime >= 1.0f) { m_ani.SetBool("idle", true); m_timer = 2; } } }
void Update() { //stop walking after reaching his target //(when the target is not an interactable) if (etat == "marche" && agent.remainingDistance <= distanceAvantArret) { agent.ResetPath(); AC.CrossFade("idle", 0.1f); etat = "idle"; } speed = Vector3.Distance(t.position, precposition); if (timeBeforeTryStopping < 0 && etat == "marche" && agent.remainingDistance < distanceAvantArret * 2 && speed < speedBeforeStop) { agent.ResetPath(); etat = "idle"; AC.CrossFade("idle", 0.1f); } timeBeforeTryStopping -= Time.deltaTime; if (etat == "marche" && main.m.lastInteractable != null) { distanceCible = Vector3.Distance(t.position, main.m.lastInteractable.transform.position); } //player is walking to an interactable if (etat == "marche" && main.m.lastInteractable != null && Vector3.Distance(t.position, main.m.lastInteractable.transform.position) < distanceAvantAction) { etat = "idle"; //Player will interact with the chair if (main.m.lastInteractable.tag == "ordi") { //Player open PC and sit (currently dance) etat = "ordinateur"; agent.ResetPath(); //Player wants to interact with the bookshelf } else if (main.m.lastInteractable.tag == "armoire") { //Player open the bookshelf (anim: pickup) etat = "armoire"; agent.ResetPath(); } else { AC.CrossFade("idle", 0.1f); agent.ResetPath(); } if (main.m.lastInteractable.tag == "PNJ") { main.m.actionPNJ(main.m.lastInteractable.name); } } precposition = t.position; }
//public void MoveUnitSprint() { //PlaySound(RunSound); // navMeshAgent.speed = 8; // navMeshAgent.acceleration = 8; //navMeshAgent.destination = dest.point; //navMeshAgent.Resume(); // myAnimator.Play("Sprint"); // } public void KillPlayer() { navMeshAgent.velocity = Vector3.zero; navMeshAgent.ResetPath(); myAnimator.Play("Death"); PlaySound(DeathSound); PlaySound(FeastSound); transform.tag = "Dead"; transform.Find("Selected marker").gameObject.SetActive(false); GetComponent <BoxCollider>().isTrigger = true; GetComponent <UnityEngine.AI.NavMeshAgent>().enabled = false; GetComponent <PlayerMovement>().enabled = false; }
IEnumerator UseQ() { agent.ResetPath(); while (!SkillQ.GetComponent <Active>().isActive) { if (animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains("attack_1") && animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 0.99f) { playerController.SetMoveable(true); } yield return(new WaitForSeconds(Time.deltaTime)); } }
void AggroPlayer() { playerDist = Vector3.Distance(transform.position, player.transform.position); eNav.updateRotation = true; //Player Spotted if (allowFollow == true && playerDist <= alertDist) { if (eNav.enabled == true) { eNav.stoppingDistance = 4.0f; eNav.speed = 2; eNav.SetDestination(player.transform.position); transform.LookAt(player.transform.position); //Follow/Attack Player if (allowAttack == true && playerDist <= attackDist) { StartCoroutine("ShootAtPlayer"); } } } else if (allowFollow == true && playerDist >= alertDist) { if (VassalList.currentVassal != null && VassalList.Vassals.Count > 0) { vassalDist = Vector3.Distance(transform.position, VassalList.currentVassal.transform.position); if (vassalDist <= alertDist && VassalList.currentVassal.GetComponent <BMVassalScript>().alive == true) { eNav.SetDestination(VassalList.currentVassal.transform.position); transform.LookAt(VassalList.currentVassal.transform.position); if (vassalDist <= attackDist) { StartCoroutine("ShootAtPlayer"); } } } } else { eNav.ResetPath(); } /* * if (eNav.pathStatus != NavMeshPathStatus.PathComplete) { * eNav.enabled = false; * } else { * if (eNav.pathStatus == NavMeshPathStatus.PathComplete && eNav.enabled == false && eNav.isOnNavMesh == true) { * eNav.enabled = true; * } * }*/ }
void Update() { // timer += Time.fixedDeltaTime; if (enemy == null) { SearchEnemy(); return; } float dist = Vector3.Distance(enemy.transform.position, transform.position); if (dist > CurSD) { nam.SetDestination(enemy.transform.position); } else { nam.ResetPath(); Vector3 dir = enemy.transform.position - transform.position; Quaternion wantedRotation = Quaternion.LookRotation(dir); transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, rotateSpeed * Time.deltaTime); } if (dist < curAR) { tw.shoot(); } }
/// <summary> /// 移动 /// </summary> /// <param name="target"></param> public void move(Vector3 target) { agent.ResetPath(); agent.SetDestination(target); anim.SetInteger("state", AnimState.RUN); state = AnimState.RUN; }
public void EmoteAnim(float delay, string animName) { AI.ResetPath(); CancelInvoke("Move"); Rig.SetTrigger(animName); Invoke("RestartAI", delay); }
private void FixedUpdate() { //First we check distance from the player currentDistance = Vector3.Distance(light.transform.position, transform.position); animator.SetFloat("distanceFromPlayer", currentDistance); //Then we check for visibility checkDirection = light.transform.position - transform.position; ray = new Ray(transform.position, checkDirection); if (Physics.Raycast(ray, out hit, maxDistanceToCheck)) { if (hit.collider.gameObject.tag == "RedLight") { navMeshAgent.ResetPath(); } if (hit.collider.gameObject.tag == "GreenLight") { navMeshAgent.SetDestination(waypoints[currentTarget].position); } } //Lastly, we get the distance to the next waypoint target distanceFromTarget = Vector3.Distance(waypoints[currentTarget].position, transform.position); animator.SetFloat("distanceFromWaypoint", distanceFromTarget); }
// Update is called once per frame void Update() { _distanceVec = _TargetTransform.position - this.transform.position; _distanceSqr = _distanceVec.sqrMagnitude; _navAgent.speed = _thisActor._ActorData._Movespeed * 0.1f; if (!_isRagdolled) { _navAgent.enabled = true; if (_distanceSqr >= 20.0f) { _navAgent.SetDestination(_TargetTransform.position); } else if (_distanceSqr <= 10.0f) { _navAgent.ResetPath(); } } else { _navAgent.enabled = false; } }
/* * 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(); } }
public void Stop() { if (Agent.isActiveAndEnabled) { Agent.Stop(); Agent.ResetPath(); } }
public void StopMoving() { _navAgent.ResetPath(); moveTarget = Vector3.zero; jumpTarget = Vector3.zero; _anim.SetBool("IsMoving", false); _anim.SetBool("IsJumping", false); }
void PathReset() { if (future >= 200) { agent.ResetPath(); future = 0; } }
public void SquadBehaviorActive(bool _pred) { if (_pred) { m_NavAgent.ResetPath(); stateQue.Clear(); } squadBehaviorActive = _pred; }
//this will run once when the script epened override protected void OpenBehaviour() { base.OpenBehaviour(); stats.getAnimalStats.getHungry = -0.1f; agent.ResetPath(); //agent.Resume(); radius = 10; //print("Open" + scriptNR); }
public void Death() { navAgent.Stop(); navAgent.ResetPath(); navAgent.enabled = false; state = State.Dead; anim.SetInteger("AnimationState", -1); Destroy(gameObject, 5); }
void ResetAgent() { speedMult = Random.Range(.5f, 1.2f); agent.speed = 2 * speedMult; agent.angularSpeed = 120; anim.SetFloat("speedMult", speedMult); anim.SetTrigger("isWalking"); agent.ResetPath(); }
public override void StopNav() { currentPathPointDistance = 0; cornersIdx = 0; speed = 0; isMovingToTarget = false; navAgent.Stop(); navAgent.ResetPath(); }
IEnumerator TurnToTargetCR(Vector3 target) { agent.velocity = Vector3.zero; agent.acceleration = 0f; agent.SetDestination(target); yield return(new WaitForSeconds(1f)); agent.ResetPath(); agent.acceleration = 8f; }
//================================================ State Helper Methods #region State Methods //--------------------------- Navmesh Agent protected void StopAgent() { if (_agent != null && _agent.enabled) { _agent.isStopped = true; _agent.velocity = Vector3.zero; _agent.ResetPath(); _agent.enabled = false; } }
// Use this for initialization void Start() { anim = transform.GetComponent <Animator>(); standBool = Animator.StringToHash("Stehen"); ritterAi = GetComponent <RitterAI>(); ritterAi.enabled = !ritterAi.enabled; agent = GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.ResetPath(); attackBool = Animator.StringToHash("attackBool"); }
// Update is called once per frame public void Update() { ShooterController.SetTarget(Target); if (Target != null && Vector3.Distance(this.transform.position, Target.transform.position) >= FollowAgroRange) { Agent.ResetPath(); this.Target.SendMessage("OnEnemyDeadOrFlee", this.GetComponent <Collider>()); Target = null; } }
public void StopAgent() { if (_agent.enabled) { _agent.isStopped = true; _agent.ResetPath(); _agent.velocity = Vector3.zero; _agent.enabled = false; _hasPath = false; } }
public void ChangeLane(Path _newPath = Path.ANY_PATH) { if (!followingNav) { m_path = Path.ANY_PATH; } else { m_path = _newPath; } if (!agent) { Start2(); } agent.areaMask = (int)m_path; if (agent.isPathStale) { agent.ResetPath(); } }
// public void Born() { targetPlayer = null; currentState = FSMState.Wander; AIHealth.currentHP = AIHealth.maxHP; agent.enabled = true; agent.ResetPath(); animator.applyRootMotion = false; GetComponent <CapsuleCollider>().enabled = true; animator.SetTrigger("toReborn"); disappearTimer = 0; disappeared = false; firstInDead = true; currentState = FSMState.Wander; }
static public int ResetPath(IntPtr l) { try { UnityEngine.AI.NavMeshAgent self = (UnityEngine.AI.NavMeshAgent)checkSelf(l); self.ResetPath(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
private void stopMove() { IsStop = true; if (!Agent || !Agent.enabled) { return; } Agent.velocity = Vector3.zero; Agent.ResetPath(); Agent.Stop(); targetPos = null; }