Collisions, AI tweaks
This commit is contained in:
@@ -52,6 +52,8 @@ public class EnemyAttack : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public float GetAttackRange() => attackRange;
|
||||
|
||||
// Metoda pro pokus o <20>tok - vol<6F>na z EnemyMovement
|
||||
public bool TryAttack()
|
||||
{
|
||||
@@ -63,19 +65,17 @@ public class EnemyAttack : MonoBehaviour
|
||||
|
||||
// Kontrola vzd<7A>lenosti a <20>hlu k hr<68><72>i
|
||||
float distanceToPlayer = Vector3.Distance(transform.position, player.position);
|
||||
bool inRange = distanceToPlayer <= attackRange;
|
||||
bool inRange = IsPlayerInAttackRange();
|
||||
bool inAngle = IsPlayerInAttackAngle();
|
||||
bool cooldownReady = Time.time - lastAttackTime >= attackRate;
|
||||
|
||||
Debug.Log($"TryAttack: range={inRange}, angle={inAngle}, cooldown={cooldownReady}, distance={distanceToPlayer}");
|
||||
|
||||
if (inRange && cooldownReady)
|
||||
{
|
||||
StartCoroutine(PerformAttack());
|
||||
return true;
|
||||
}
|
||||
|
||||
Debug.Log("Attack conditions not met");
|
||||
Debug.Log("Attack conditions not met. Conditions: range: " + inRange + "angle: " + inAngle + "cooldown: " + cooldownReady);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,10 +100,9 @@ public class EnemyAttack : MonoBehaviour
|
||||
if (player == null) return false;
|
||||
|
||||
float distance = Vector3.Distance(transform.position, player.position);
|
||||
bool inRange = distance <= attackRange * 1.1f;
|
||||
bool inAngle = IsPlayerInAttackAngle();
|
||||
bool inRange = distance <= attackRange * 1.2f;
|
||||
|
||||
return inRange && inAngle;
|
||||
return inRange;
|
||||
}
|
||||
|
||||
private IEnumerator PerformAttack()
|
||||
@@ -126,7 +125,7 @@ public class EnemyAttack : MonoBehaviour
|
||||
}
|
||||
|
||||
// Po<50>kej chv<68>li p<>ed aplikov<6F>n<EFBFBD>m po<70>kozen<65>
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
bool playerDashing = skillHandler.IsDashing();
|
||||
// Aplikuj po<70>kozen<65>, pokud je hr<68><72> st<73>le v dosahu
|
||||
@@ -141,7 +140,7 @@ public class EnemyAttack : MonoBehaviour
|
||||
}
|
||||
|
||||
// Po<50>kej na dokon<6F>en<65> animace
|
||||
yield return new WaitForSeconds(0.7f);
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
|
||||
// Obnov pohyb pouze pokud nebyl p<>vodn<64> zastaven<65>
|
||||
if (!wasStopped)
|
||||
@@ -173,7 +172,7 @@ public class EnemyAttack : MonoBehaviour
|
||||
// Public metody pro komunikaci s EnemyMovement
|
||||
public bool CanAttack()
|
||||
{
|
||||
return canAttack && !isAttacking;
|
||||
return canAttack && !isAttacking && IsPlayerInAttackRange();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ public class EnemyMovement : MonoBehaviour
|
||||
public float roomCheckInterval = 2f;
|
||||
|
||||
[Header("Combat")]
|
||||
public float attackRange = 2f;
|
||||
public float sightRange = 20f;
|
||||
public float patrolRange = 5f;
|
||||
|
||||
@@ -24,6 +23,7 @@ public class EnemyMovement : MonoBehaviour
|
||||
private Vector3 patrolTarget;
|
||||
private float lastStateChangeTime;
|
||||
private float minAttackStateDuration = 1.0f;
|
||||
private float attackRange;
|
||||
|
||||
[Header("Animation")]
|
||||
public Animator animator;
|
||||
@@ -32,6 +32,8 @@ public class EnemyMovement : MonoBehaviour
|
||||
{
|
||||
// Najdi hr<68><72>e
|
||||
GameObject playerObject = GameObject.FindWithTag("Player");
|
||||
attackRange = enemyAttack.GetAttackRange();
|
||||
|
||||
if (playerObject != null)
|
||||
{
|
||||
player = playerObject.transform;
|
||||
@@ -148,13 +150,13 @@ public class EnemyMovement : MonoBehaviour
|
||||
float distanceToPlayer = Vector3.Distance(transform.position, player.position);
|
||||
|
||||
// Z<>sta<74> v attack stavu pokud m<><6D>e <20>to<74>it nebo se ot<6F><74><EFBFBD> k hr<68><72>i
|
||||
if (!attackAttempted && enemyAttack.CanAttack() && enemyAttack.IsPlayerInAttackRange())
|
||||
if (attackAttempted && enemyAttack.CanAttack())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Pokud je hr<68><72> p<><70>li<6C> daleko, pokra<72>uj v pron<6F>sledov<6F>n<EFBFBD>
|
||||
if (distanceToPlayer > attackRange * 1.5f && !enemyAttack.IsAttacking())
|
||||
if (distanceToPlayer > attackRange && !enemyAttack.IsAttacking())
|
||||
{
|
||||
ChangeState(EnemyState.Chasing);
|
||||
}
|
||||
@@ -182,7 +184,7 @@ public class EnemyMovement : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,39 +271,39 @@ public class EnemyMovement : MonoBehaviour
|
||||
|
||||
|
||||
/*====== FOR DEBUGGING PURPOSES ONLY ========== */
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(transform.position, attackRange);
|
||||
//private void OnDrawGizmosSelected()
|
||||
//{
|
||||
// Gizmos.color = Color.red;
|
||||
// Gizmos.DrawWireSphere(transform.position, attackRange);
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(transform.position, sightRange);
|
||||
// Gizmos.color = Color.yellow;
|
||||
// Gizmos.DrawWireSphere(transform.position, sightRange);
|
||||
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawWireSphere(patrolCenter, patrolRange);
|
||||
// Gizmos.color = Color.blue;
|
||||
// Gizmos.DrawWireSphere(patrolCenter, patrolRange);
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawSphere(patrolTarget, 0.3f);
|
||||
Gizmos.DrawLine(transform.position, patrolTarget);
|
||||
}
|
||||
}
|
||||
// if (Application.isPlaying)
|
||||
// {
|
||||
// Gizmos.color = Color.green;
|
||||
// Gizmos.DrawSphere(patrolTarget, 0.3f);
|
||||
// Gizmos.DrawLine(transform.position, patrolTarget);
|
||||
// }
|
||||
//}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (Application.isPlaying && enemyAttack != null)
|
||||
{
|
||||
GUI.Label(new Rect(10, 30, 300, 20), $"State: {currentState}");
|
||||
GUI.Label(new Rect(10, 50, 300, 20), $"CanAttack: {enemyAttack.CanAttack()}");
|
||||
GUI.Label(new Rect(10, 70, 300, 20), $"IsAttacking: {enemyAttack.IsAttacking()}");
|
||||
GUI.Label(new Rect(10, 90, 300, 20), $"Cooldown: {enemyAttack.GetCooldownProgress():P0}");
|
||||
//private void OnGUI()
|
||||
//{
|
||||
// if (Application.isPlaying && enemyAttack != null)
|
||||
// {
|
||||
// GUI.Label(new Rect(10, 30, 300, 20), $"State: {currentState}");
|
||||
// GUI.Label(new Rect(10, 50, 300, 20), $"CanAttack: {enemyAttack.CanAttack()}");
|
||||
// GUI.Label(new Rect(10, 70, 300, 20), $"IsAttacking: {enemyAttack.IsAttacking()}");
|
||||
// GUI.Label(new Rect(10, 90, 300, 20), $"Cooldown: {enemyAttack.GetCooldownProgress():P0}");
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
float distance = Vector3.Distance(transform.position, player.position);
|
||||
GUI.Label(new Rect(10, 110, 300, 20), $"Distance: {distance:F2}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (player != null)
|
||||
// {
|
||||
// float distance = Vector3.Distance(transform.position, player.position);
|
||||
// GUI.Label(new Rect(10, 110, 300, 20), $"Distance: {distance:F2}");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -276,7 +276,6 @@ public class MapGenManager : MonoBehaviour
|
||||
|
||||
// Bake globální NavMesh
|
||||
globalNavMeshSurface.BuildNavMesh();
|
||||
Debug.Log("Global NavMesh baked");
|
||||
}
|
||||
|
||||
/* ============================================================ */
|
||||
|
||||
Reference in New Issue
Block a user