Dash tweaks, quality of code
This commit is contained in:
@@ -15,10 +15,12 @@ public class EnemyAttack : MonoBehaviour
|
|||||||
[SerializeField] private Animator animator;
|
[SerializeField] private Animator animator;
|
||||||
[SerializeField] private NavMeshAgent agent;
|
[SerializeField] private NavMeshAgent agent;
|
||||||
|
|
||||||
|
|
||||||
private float lastAttackTime = 0f;
|
private float lastAttackTime = 0f;
|
||||||
private bool canAttack = true;
|
private bool canAttack = true;
|
||||||
private bool isAttacking = false;
|
private bool isAttacking = false;
|
||||||
private float attackCooldownTimer = 0f;
|
private float attackCooldownTimer = 0f;
|
||||||
|
private PlayerSkillHandler skillHandler;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@@ -29,6 +31,8 @@ public class EnemyAttack : MonoBehaviour
|
|||||||
player = playerObject.transform;
|
player = playerObject.transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skillHandler = player.GetComponent<PlayerSkillHandler>();
|
||||||
|
|
||||||
if (animator == null) animator = GetComponent<Animator>();
|
if (animator == null) animator = GetComponent<Animator>();
|
||||||
if (agent == null) agent = GetComponent<NavMeshAgent>();
|
if (agent == null) agent = GetComponent<NavMeshAgent>();
|
||||||
|
|
||||||
@@ -88,7 +92,6 @@ public class EnemyAttack : MonoBehaviour
|
|||||||
|
|
||||||
float angle = Vector3.Angle(forward, directionToPlayer);
|
float angle = Vector3.Angle(forward, directionToPlayer);
|
||||||
|
|
||||||
// Vìtší tolerance úhlu (zvýšeno z 22.5° na 60°)
|
|
||||||
return angle <= attackAngle; // Používáme celý attackAngle, ne polovinu
|
return angle <= attackAngle; // Používáme celý attackAngle, ne polovinu
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,8 +128,9 @@ public class EnemyAttack : MonoBehaviour
|
|||||||
// Poèkej chvíli pøed aplikováním poškození
|
// Poèkej chvíli pøed aplikováním poškození
|
||||||
yield return new WaitForSeconds(0.3f);
|
yield return new WaitForSeconds(0.3f);
|
||||||
|
|
||||||
|
bool playerDashing = skillHandler.IsDashing();
|
||||||
// Aplikuj poškození, pokud je hráè stále v dosahu
|
// Aplikuj poškození, pokud je hráè stále v dosahu
|
||||||
if (player != null && Vector3.Distance(transform.position, player.position) <= attackRange * 1.2f)
|
if (player != null && Vector3.Distance(transform.position, player.position) <= attackRange * 1.2f && !playerDashing)
|
||||||
{
|
{
|
||||||
var health = player.GetComponent<HealthManager>();
|
var health = player.GetComponent<HealthManager>();
|
||||||
if (health != null)
|
if (health != null)
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ public class EnemyMovement : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========= PATROLLING IN CASE PLAYER IS FAR ========== */
|
||||||
private void GenerateNewPatrolTarget()
|
private void GenerateNewPatrolTarget()
|
||||||
{
|
{
|
||||||
Vector2 randomCircle = Random.insideUnitCircle * patrolRange;
|
Vector2 randomCircle = Random.insideUnitCircle * patrolRange;
|
||||||
@@ -266,6 +267,8 @@ public class EnemyMovement : MonoBehaviour
|
|||||||
Destroy(gameObject, 2f);
|
Destroy(gameObject, 2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*====== FOR DEBUGGING PURPOSES ONLY ========== */
|
||||||
private void OnDrawGizmosSelected()
|
private void OnDrawGizmosSelected()
|
||||||
{
|
{
|
||||||
Gizmos.color = Color.red;
|
Gizmos.color = Color.red;
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class PlayerSkillHandler: MonoBehaviour
|
|||||||
yield return null; // wait one frame
|
yield return null; // wait one frame
|
||||||
}
|
}
|
||||||
handleCooldownTimer(PlayerSkillTree.Skills.Dash);
|
handleCooldownTimer(PlayerSkillTree.Skills.Dash);
|
||||||
|
yield return new WaitForSeconds(0.5f);
|
||||||
isDashing = false; // just for now. maybe will be removed
|
isDashing = false; // just for now. maybe will be removed
|
||||||
Physics.IgnoreLayerCollision(6, 7, false); // enable collisions between player and enemies
|
Physics.IgnoreLayerCollision(6, 7, false); // enable collisions between player and enemies
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user