/// <summary> /// Overloaded method with an optional parameter for toggling agent updates. /// <summary> public void Stop(bool stopUpdates) { StopAllCoroutines(); //reset current waypoint index to zero currentPoint = 0; agent.Stop(stopUpdates); }
public virtual void handleAttack() { if (explodeOnAttack) { CameraShake cs = (CameraShake)GameObject.FindObjectOfType(typeof(CameraShake)); if (cs) { cs.shake(); } m_damagable.killSelf(); } if (m_animator) { m_animator.SetBool("Attack", true); } if (m_agent && m_agent.isOnNavMesh) { m_agent.Stop(); } Damagable dam = m_target.GetComponent <Damagable>(); if (dam) { dam.damage(attackDamage, Damagable.DamagableType.MELEE); } m_attackTime = attackTime; }
/// <summary> /// Pauses the current movement routine for a defined amount of time. /// <summary> public void Pause(float seconds = 0f) { StopCoroutine(Wait()); waiting = true; agent.Stop(); if (seconds > 0) { StartCoroutine(Wait(seconds)); } }
void FinishAction() { if (currentNavAgent != null) { switch (currentNavAction) { case NavAgentActions.SetDestination: if (!preCalcPaths) { currentNavAgent.SetDestination(currentNavDest); } currentNavAgent.speed = currentNavSpeed; //Debug.Log("Set Nav dest"); break; case NavAgentActions.Stop: currentNavAgent.Stop(); break; case NavAgentActions.Warp: currentNavAgent.Warp(currentNavDest); break; } } else { Debug.LogWarning("No current Nav Agent was found"); } }
public override Status Update() { if (!memory) { return(Status.Error); } ITarget target = MemoryTarget(); if (target == null) { return(Status.Failure); } Vector3 targetPos = MemoryTargetPosition(target); float dis = Vector3.Distance(self.transform.position, targetPos); if (dis < disAsArrive) { agent.Stop(); return(Status.Success); } agent.SetDestination(targetPos); agent.Resume(); return(Status.Running); }
private IEnumerator DyingSequence() { // Wait a frame to avoid any conflicts with other scripts. yield return(null); // Turn off the character control and collider. m_AiCharacter.enabled = false; m_Collider.enabled = false; // Start the dying animation playing. m_Animator.SetTrigger(m_HashDyingPara); // Stop the NavMeshAgent from moving the character. m_Agent.Stop(); // In order play the clips of the player being hit and then dying. yield return(StartCoroutine(PlayClipAndWait(m_PlayerHitClip))); yield return(StartCoroutine(PlayClipAndWait(m_PlayerDieClip))); // If there are any subscribers to OnPlayerShot, call it. if (OnPlayerShot != null) { OnPlayerShot(); } }
public void StopMove() { if (_navMesh != null && _navMesh.enabled) { _navMesh.Stop(); } }
void ToggleController() { CharacterController charPlayer = objectToMove.GetComponent <CharacterController>(); UnityEngine.AI.NavMeshAgent navAgent = objectToMove.GetComponent <UnityEngine.AI.NavMeshAgent>(); switch (agent) { case AgentType.NavMeshAgent: if (navAgent != null) { navAgent.enabled = true; navAgent.Resume(); } break; case AgentType.CharacterController: if (navAgent != null && navAgent.isOnNavMesh) { navAgent.Stop(); navAgent.enabled = false; } break; } }
IEnumerator AgentMoveTo() { UnityEngine.AI.NavMeshAgent navAgent = objectToMove.GetComponent <UnityEngine.AI.NavMeshAgent>(); if (navAgent != null) { ToggleController(); Vector3 targetPos = moveToTarget.position; targetPos.y = objectToMove.position.y; navAgent.SetDestination(targetPos); while (true) { EventRepeat(); if (Vector3.Distance(objectToMove.transform.position, targetPos) <= 0.4f) { break; } yield return(null); } navAgent.Stop(); EventEnd(); } }
/// <summary>Abort method of MoveToRandomPosition </summary> /// <remarks>When the task is aborted, it stops the navAgentMesh.</remarks> public override void OnAbort() { #if UNITY_5_6_OR_NEWER navAgent.isStopped = true; #else navAgent.Stop(); #endif }
void DoStop() { if (_agent == null) { return; } _agent.Stop(); }
public override Status Update() { // Get the agent UnityEngine.AI.NavMeshAgent agent = gameObject.Value != null?gameObject.Value.GetComponent <UnityEngine.AI.NavMeshAgent>() : null; // Validate members if (agent == null) { return(Status.Error); } #if UNITY_4 || UNITY_4_1 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 agent.Stop(stopUpdates.Value); #else agent.Stop(); #endif return(Status.Success); }
/// <summary> /// Stop pathfinding. /// </summary> private void Stop() { if (navMeshAgent.hasPath) { #if UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5 navMeshAgent.Stop(); #else navMeshAgent.isStopped = true; #endif } }
public override TaskStatus OnUpdate() { if (navMeshAgent == null) { Debug.LogWarning("NavMeshAgent is null"); return(TaskStatus.Failure); } navMeshAgent.Stop(); return(TaskStatus.Success); }
/// <summary> /// This method updates the NavMesh Agent thus allowing the enemy to move. /// If the player is within the enemy's range then the enemy will move towards /// the player. Otherwhise he will stop. If the player is within melee range /// then the enemy will always face the player. /// </summary> void Movement() { distance = Vector3.Distance(player.position, transform.position); if (Physics.Raycast(collider.transform.TransformPoint(collider.center), playerDir, out hitInfo, viewLenght) && hitInfo.transform.tag == "Player" && distance > attackDistance) { Debug.Log("Player is in range and the enemy is following him"); nav.SetDestination(player.position); nav.Resume(); } else if (distance < attackDistance) { Debug.Log("The enemy is close enough to attack"); nav.Stop(true); transform.LookAt(player.transform); } else if (distance > viewDistance) { nav.Stop(true); } }
/// <summary>Abort method of MoveToPosition.</summary> /// <remarks>When the task is aborted, it stops the navAgentMesh.</remarks> public override void OnAbort() { #if UNITY_5_6_OR_NEWER if (navAgent != null) { navAgent.isStopped = true; } #else if (navAgent != null) { navAgent.Stop(); } #endif }
public void Update() { // Get the mouse pressed position in world. if ((Input.GetAxis("Fire1") > 0 || Input.GetAxis("Fire2") > 0) && !isMouseHovering(Input.mousePosition, guiRect, guiRectYFromBottom)) { Ray ray = myCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, rayCastDisntance, layerMask)) { currentMoveToPos = hit.point; //Check if character not already at target position then move if (Vector3.Distance(myTransform.position, currentMoveToPos) > distanceError) { hasTargetPosition = true; } } buttonDown = true; } else { buttonDown = false; } // Was a successful move enabled. if (hasTargetPosition) { // Move to target location. navMeshAgent.SetDestination(currentMoveToPos); if (animator != null) { animator.SetBool("run", true); } // Calculate distance to target location and stop if in range. if (Vector3.Distance(myTransform.position, currentMoveToPos) <= distanceError && !buttonDown) { hasTargetPosition = false; if (animator != null) { animator.SetBool("run", false); } navMeshAgent.Stop(); } } }
public void StopLocomotionWithAgent() { if (!agent) { return; } if (agent.enabled) { agent.Stop(); } agent.enabled = false; IsMovingWithAgent = false; }
/// <summary> /// Clears all the target properties /// </summary> public void ClearTarget() { if (_ClearTargetOnStop) { _Target = null; _TargetPosition = Vector3Ext.Null; mIsTargetSet = false; } mNavMeshAgent.Stop(); mHasArrived = false; mFirstPathSet = false; mFirstPathValid = false; mIsInSlowDistance = false; mActorController.SetRelativeVelocity(Vector3.zero); }
public override Status Update() { BaseAIParameters param = self.GetComponent <BaseAIParameters>(); if (!param) { return(Status.Error); } //if (Vector3.Distance(self.transform.position, param.targetVector) < 2) //{ // return Status.Success; //} UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.Stop(); //agent.SetDestination(param.targetVector); return(Status.Success); }
public override Status Update() { //BaseAIParameters param = self.GetComponent<BaseAIParameters>(); //if (!param || !param.destinationEnable) //{ // return Status.Failure; //} //if (Vector3.Distance(self.transform.position, param.destination) < param.endSeekingDistance) //{ // return Status.Success; //} Memory memory = self.GetComponent <Memory>(); if (!memory) { return(Status.Failure); } ITarget[] targets = memory.AllTargets(); bool hasTarget = targets.Length > 0; if (hasTarget) { ITarget target = targets[0]; IMemorable memorable = target as IMemorable; IMemorableItem memItem = memory.Find(memorable); Vector3 destination = memItem.lastOccurPosition; UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.SetDestination(destination); agent.Resume(); return(Status.Running); } else { UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.Stop(); return(Status.Failure); } }
/// <summary> /// Clears all the target properties /// </summary> public void ClearTarget() { _Target = null; _TargetPosition = Vector3Ext.Null; mNavMeshAgent.Stop(); mHasArrived = false; mFirstPathSet = false; mFirstPathValid = false; mIsInSlowDistance = false; mIsTargetSet = false; mViewX = 0f; mViewY = 0f; mMovementX = 0f; mMovementY = 0f; mInputFromAvatarAngle = 0f; mInputFromCameraAngle = 0f; }
void ArrivedEvent_Enter() { agent.Stop(); // Debug.Log("Pursue => ArrivedEvent"); }
public void PausePatrol() { IsPaused = true; _navMeshAgent.Stop(); }
public override void OnAbort() { navAgent.Stop(); }
public bool Stop() { navMeshAgent.Stop(); return(true); }
} // StartPatrolling void StopPatrolling() { General.Logger.LogDetail("AI", "StopPatrolling", "Entering function."); animator.SetBool(ANIMATION_IS_PATROLLING, false); navMeshAgent.Stop(); } // StopPatrolling
public override Status Update() { UnityEngine.AI.NavMeshAgent agent = self.GetComponent <UnityEngine.AI.NavMeshAgent>(); agent.Stop(); return(Status.Success); }
void Finish_Enter() { agent.Stop(); // Debug.Log("Patrol => Finish_Enter"); }
public override void OnEnd() { navMeshAgent.Stop(); }