// Update is called once per frame public override void OnUpdate(float deltaTime) { //only flee if target is in flee range //flee away from target //stop when in safe distance if (m_currentReactionTime < m_reactionTimer) { m_currentReactionTime += Time.deltaTime; } else { m_currentReactionTime = 0.0f; if (m_agentController.IsTargetWithinFleeRange()) { CalculateSafeFleeDestination(); } else { m_agentController.currentDestination = Vector3.zero; m_agentController.StopAllMovement(); } } m_agentController.MoveTowardsDestination(); }
// Update is called once per frame public override void OnUpdate(float deltaTime) { float radius = 1.5f; NavMeshHit hit; if (NavMesh.SamplePosition(m_agentController.m_chaseTarget.position, out hit, radius, NavMesh.AllAreas)) { m_agentController.currentDestination = hit.position; } else { //no navmesh found m_agentController.currentDestination = Vector3.zero; m_agentController.StopAllMovement(); } m_agentController.MoveTowardsDestination(); }