/// <summary> /// Sets the new destination that we need to travel to /// </summary> /// <param name="rDestination"></param> protected virtual void SetDestination(Vector3 rDestination) { if (!mHasArrived && mAgentDestination == rDestination) { return; } // Reset the properties mHasArrived = false; // Set the new destination mAgentDestination = rDestination; // Recalculate the path if (!mNavMeshAgent.pathPending) { mNavMeshAgent.updatePosition = false; mNavMeshAgent.updateRotation = false; mNavMeshAgent.stoppingDistance = _StopDistance; mNavMeshAgent.ResetPath(); mNavMeshAgent.SetDestination(mAgentDestination); mFirstPathSet = true; } }
public override void End() { if ((resetPath.isNone || resetPath.Value) && m_GOAgent != null && m_GOAgent.hasPath && gameObject.Value != null) { m_GOAgent.ResetPath(); } }
void DoResetPath() { if (_agent == null) { return; } _agent.ResetPath(); }
void PauseNavMeshAgent(int dummy) { if (myNavMeshAgent != null && myNavMeshAgent.enabled) { myNavMeshAgent.ResetPath(); enemyMaster.isNavPaused = true; StartCoroutine(RestartNavMeshAgent()); } }
public void NavigateTo(Vector3 position, Action callback) { navAgent.ResetPath(); navAgent.SetDestination(position); running = true; reachedCallback = callback; frontAnim.Run(); backAnim.Run(); }
public override TaskStatus OnUpdate() { if (navMeshAgent == null) { Debug.LogWarning("NavMeshAgent is null"); return(TaskStatus.Failure); } navMeshAgent.ResetPath(); return(TaskStatus.Success); }
public override void Stop() { base.Stop(); if (useNavMeshAgent && navMeshAgent && navMeshAgent.isOnNavMesh && !navMeshAgent.isStopped) { //_turnOnSpotDirection = transform.forward; //temporaryDirection = transform.forward; navMeshAgent.isStopped = true; this.destination = transform.position; ForceUpdatePath(); navMeshAgent.ResetPath(); } }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions /// <summary> /// Target One player and do in range action. /// </summary> /// <param name="target"> Target we are following. </param> public void TargetOne(Transform target) { // if target is does not exist, // end function call. if (target == null) { JCS_Debug.LogError( "This transform u are targeting are null..."); return; } if (mSearchCount == 2) { // reset search count. mSearchCount = 0; // exit out of recursive function call... return; } // reset the path every time it request. mNavMeshAgent.ResetPath(); // calculate the distance and range relationship, // and find out the position enemy are approach to. Vector3 targetPos = CalculateRange(target.transform.position); // set to the destination. bool found = mNavMeshAgent.SetDestination(targetPos); // increase the search count. ++mSearchCount; // if faild, try it again. if (!found) { TargetOne(target); } else { // if succesed. // reset search count. mSearchCount = 0; } // make sure the action is approve. mTargeted = true; }
// Update is called once per frame void FixedUpdate() { if (targetTeamPlayer == null) { readyToAttack = false; //if(!reset) { //agent.ResetPath(); //StartCoroutine(waitOneSecond()); } return; } Vector3 targetPos = targetTeamPlayer.gameObject.transform.position; float mag = (targetPos - character.transform.position).magnitude; bool inAttackRange = mag < attackRange; bool inBestAttackRange = mag < stopRange; if (inAttackRange) { if (readyToAttack) { Vector3 dir = targetPos - character.transform.position; RaycastHit hit; if (Physics.Raycast(eyes.transform.position, dir, out hit)) { if (hit.collider.gameObject == targetTeamPlayer.gameObject) { agent.ResetPath(); if (initiativeEquipment != null) { Vector3 currentDir = Vector3.Lerp(initiativeEquipmentRoot.transform.forward, dir, _aimSpeed); initiativeEquipmentRoot.transform.rotation = Quaternion.LookRotation(currentDir); //瞄准玩家攻击 initiativeEquipment.FunctionBtnInput(character, BtnType.Main1, BtnInputType.Down); currentDir = Vector3.Lerp(transform.forward, dir, _aimSpeed); currentDir.y = 0; character.transform.rotation = Quaternion.LookRotation(currentDir); } } else { initiativeEquipment.FunctionBtnInput(character, BtnType.Main1, BtnInputType.Up); agent.SetDestination(targetPos); } } else { initiativeEquipment.FunctionBtnInput(character, BtnType.Main1, BtnInputType.Up); agent.SetDestination(targetPos); } } else { if (inBestAttackRange) { readyToAttack = true; } else { readyToAttack = false; initiativeEquipment.FunctionBtnInput(character, BtnType.Main1, BtnInputType.Up); agent.SetDestination(targetPos); } } } else { readyToAttack = false; initiativeEquipment.FunctionBtnInput(character, BtnType.Main1, BtnInputType.Up); agent.SetDestination(targetPos); } }
public override void OnStart() { UnityEngine.AI.NavMeshAgent agent = entity.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.ResetPath(); }