diff --git a/Assets/Prefab/Enemy/Bondowoso.prefab b/Assets/Prefab/Enemy/Bondowoso.prefab index 5e514a845f03b2c0c40bcdd699af45684738f383..5df316c85d79197960a1ab8256886c4c56b2d7f7 100644 --- a/Assets/Prefab/Enemy/Bondowoso.prefab +++ b/Assets/Prefab/Enemy/Bondowoso.prefab @@ -114,7 +114,7 @@ NavMeshAgent: m_AutoRepath: 1 m_Height: 7 m_BaseOffset: 0 - m_WalkableMask: 5 + m_WalkableMask: 1 m_ObstacleAvoidanceType: 4 --- !u!114 &-1231610468905177093 MonoBehaviour: @@ -151,8 +151,8 @@ MonoBehaviour: m_EditorClassIdentifier: visionRadius: 100 attackRadius: 20 - patrolRadius: 20 - patrolDistanceLimit: 10 + patrolRadius: 25 + patrolDistanceLimit: 20 rotationSpeed: 5 attackCooldownTime: 3 enemyAnimator: {fileID: 1029985441028286264} diff --git a/Assets/Prefab/Enemy/Jenderal.prefab b/Assets/Prefab/Enemy/Jenderal.prefab index 369ce1e2c554c32761ef23d3ada327b4a23bf4df..6dafa7f173aab73478493186fee750be4e17b40d 100644 --- a/Assets/Prefab/Enemy/Jenderal.prefab +++ b/Assets/Prefab/Enemy/Jenderal.prefab @@ -111,7 +111,7 @@ NavMeshAgent: m_AutoRepath: 1 m_Height: 5 m_BaseOffset: 0 - m_WalkableMask: 4294967295 + m_WalkableMask: 1 m_ObstacleAvoidanceType: 4 --- !u!114 &4709834490000420793 MonoBehaviour: @@ -148,8 +148,8 @@ MonoBehaviour: m_EditorClassIdentifier: visionRadius: 75 attackRadius: 5 - patrolRadius: 15 - patrolDistanceLimit: 8 + patrolRadius: 25 + patrolDistanceLimit: 20 rotationSpeed: 5 attackCooldownTime: 2 enemyAnimator: {fileID: 7283786664019546727} diff --git a/Assets/Prefab/Enemy/KepalaKeroco.prefab b/Assets/Prefab/Enemy/KepalaKeroco.prefab index 08f54619760143650d884161a5e471386984a27f..0ed481516ac3e3f1f9a7004d3cf921ef8589e188 100644 --- a/Assets/Prefab/Enemy/KepalaKeroco.prefab +++ b/Assets/Prefab/Enemy/KepalaKeroco.prefab @@ -127,7 +127,7 @@ MonoBehaviour: visionRadius: 50 attackRadius: 15 patrolRadius: 20 - patrolDistanceLimit: 10 + patrolDistanceLimit: 15 rotationSpeed: 5 attackCooldownTime: 3 enemyAnimator: {fileID: 4075058093763895821} @@ -152,7 +152,7 @@ NavMeshAgent: m_AutoRepath: 1 m_Height: 3.68 m_BaseOffset: 0 - m_WalkableMask: 4294967295 + m_WalkableMask: 1 m_ObstacleAvoidanceType: 4 --- !u!82 &-6884356819932166858 AudioSource: diff --git a/Assets/Prefab/Enemy/Keroco.prefab b/Assets/Prefab/Enemy/Keroco.prefab index 6f7c64efee50d7d1d36741bf373de18969b38cee..f279d74b376882636ff7712adb1495b9990a6d06 100644 --- a/Assets/Prefab/Enemy/Keroco.prefab +++ b/Assets/Prefab/Enemy/Keroco.prefab @@ -108,7 +108,7 @@ NavMeshAgent: m_AutoRepath: 1 m_Height: 3.5 m_BaseOffset: 0 - m_WalkableMask: 4294967295 + m_WalkableMask: 1 m_ObstacleAvoidanceType: 4 --- !u!114 &2406453993655408128 MonoBehaviour: @@ -145,8 +145,8 @@ MonoBehaviour: m_EditorClassIdentifier: visionRadius: 50 attackRadius: 4 - patrolRadius: 10 - patrolDistanceLimit: 5 + patrolRadius: 15 + patrolDistanceLimit: 10 rotationSpeed: 5 attackCooldownTime: 3 enemyAnimator: {fileID: 3386647410158969942} diff --git a/Assets/Scripts/Enemy/EnemyMovement.cs b/Assets/Scripts/Enemy/EnemyMovement.cs index ce92ec3763f71a9e551bbbb2803cac4393e3de10..26b1df5a7aca8d8a3ca9cea8221f5c8d64bd4e1c 100644 --- a/Assets/Scripts/Enemy/EnemyMovement.cs +++ b/Assets/Scripts/Enemy/EnemyMovement.cs @@ -16,14 +16,12 @@ public class EnemyMovement : MonoBehaviour private float lastAttackTime; private Transform player; private NavMeshAgent agent; - private Vector3 lastPatrolPosition; private AudioSource audioSource; void Awake() { player = GameObject.FindGameObjectWithTag("Player")?.transform; agent = GetComponent<NavMeshAgent>(); - lastPatrolPosition = transform.position; agent.updateRotation = false; lastAttackTime = Time.time; audioSource = GetComponent<AudioSource>(); @@ -109,15 +107,19 @@ public class EnemyMovement : MonoBehaviour enemyAnimator.SetBool("isAttacking", false); enemyAnimator.SetBool("isChasing", false); enemyAnimator.SetBool("isPatrolling", true); - if (Vector3.Distance(transform.position, lastPatrolPosition) >= patrolDistanceLimit) + + // Check if the enemy has reached the current patrol destination + if (!agent.pathPending && agent.remainingDistance < 0.5f) { - Vector2 randomDirection = Random.insideUnitCircle.normalized * patrolRadius; - Vector3 randomPos = transform.position + new Vector3(randomDirection.x, 0, randomDirection.y); - NavMeshHit hit; - if (NavMesh.SamplePosition(randomPos, out hit, patrolRadius, 1)) + // Generate a new random patrol destination + Vector3 randomDirection = Random.insideUnitSphere * patrolRadius; + randomDirection += transform.position; + + // Ensure the new destination is on the NavMesh + if (NavMesh.SamplePosition(randomDirection, out NavMeshHit hit, patrolRadius, 1)) { - lastPatrolPosition = hit.position; - agent.SetDestination(lastPatrolPosition); + RotateTowards(hit.position); + agent.SetDestination(hit.position); } } }