какашки мне в кармашки
This commit is contained in:
1 parent
7fba61f7a0
commit
cbda26dfc0
335 files changed
+51926
-7266
No files matched your search
@@ -17,17 +17,24 @@ public class BlindMutantAI : MonoBehaviour
|
||||
private float waitTimer = 0f;
|
||||
private int currentPatrolIndex;
|
||||
private bool isInvestigating = false;
|
||||
private float investigationTimer = 0f;
|
||||
|
||||
[Header("Режим охраны комнаты")]
|
||||
[Tooltip("Если включено, мутант приписан к комнате и патрулирует строго ее, но реагирует на звуки снаружи")]
|
||||
public bool isRoomConfined = false;
|
||||
|
||||
[Header("Обнаружение игрока")]
|
||||
public float detectionRadius = 3.5f; // Радиус обостренных чувств (слух/запах в упор)
|
||||
public float losePlayerDistance = 14f; // Дистанция потери цели
|
||||
private Transform targetPlayer;
|
||||
private PlayerHealth targetPlayerHealth;
|
||||
private EchoTrigger echoTrigger;
|
||||
private float silentPlayerTimer = 0f;
|
||||
|
||||
[Header("Настройки атаки")]
|
||||
public float attackRange = 1.8f; // Дистанция ближнего боя
|
||||
public float attackDamage = 20f; // Урон за один удар
|
||||
public float attackCooldown = 1.2f; // Кулдаун между ударами
|
||||
public float attackDamage = 8f; // Урон за один удар (снижен с 20 для баланса)
|
||||
public float attackCooldown = 1.35f; // Кулдаун между ударами
|
||||
private float nextAttackTime = 0f;
|
||||
|
||||
void Start()
|
||||
@@ -36,6 +43,8 @@ public class BlindMutantAI : MonoBehaviour
|
||||
if (agent != null)
|
||||
{
|
||||
agent.speed = walkSpeed;
|
||||
// Слегка варьируем приоритет избегания, чтобы мутанты уступали друг другу дорогу
|
||||
agent.avoidancePriority = Random.Range(30, 70);
|
||||
|
||||
// Если агент чуть выше пола или не на сетке, привязываем его к ближайшей точке NavMesh
|
||||
if (!agent.isOnNavMesh)
|
||||
@@ -56,12 +65,24 @@ public class BlindMutantAI : MonoBehaviour
|
||||
targetPlayerHealth = playerObj;
|
||||
}
|
||||
|
||||
if (echoTrigger == null)
|
||||
{
|
||||
echoTrigger = FindAnyObjectByType<EchoTrigger>();
|
||||
}
|
||||
|
||||
// Если точки патрулирования не заданы или массив состоит из null, ищем PatrolWaypoints на сцене
|
||||
if (IsPatrolArrayEmptyOrNull())
|
||||
{
|
||||
AutoAssignPatrolWaypoints();
|
||||
}
|
||||
|
||||
// Рассинхронизируем начальные точки и таймеры, чтобы толпа мутантов не двигалась синхронно
|
||||
if (patrolPoints != null && patrolPoints.Length > 0)
|
||||
{
|
||||
currentPatrolIndex = Random.Range(0, patrolPoints.Length);
|
||||
}
|
||||
waitTimer = Random.Range(0.2f, waitTimeAtPoint);
|
||||
|
||||
GoToNextPatrolPoint();
|
||||
}
|
||||
|
||||
@@ -114,6 +135,33 @@ public class BlindMutantAI : MonoBehaviour
|
||||
animator.SetFloat("Speed", currentSpeed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверяет, стоит ли игрок неподвижно и без звуков (шейдер волн эхолокации не активен)
|
||||
/// </summary>
|
||||
public bool IsPlayerSilentAndStill()
|
||||
{
|
||||
if (echoTrigger == null)
|
||||
{
|
||||
echoTrigger = EchoTrigger.Instance != null ? EchoTrigger.Instance : FindAnyObjectByType<EchoTrigger>();
|
||||
}
|
||||
|
||||
if (echoTrigger != null)
|
||||
{
|
||||
return !echoTrigger.IsPlayerMakingNoise();
|
||||
}
|
||||
|
||||
// Резервная проверка, если EchoTrigger не найден
|
||||
if (targetPlayerHealth != null)
|
||||
{
|
||||
var cc = targetPlayerHealth.GetComponent<CharacterController>();
|
||||
if (cc != null && cc.velocity.sqrMagnitude > 0.05f) return false;
|
||||
var anim = targetPlayerHealth.GetComponentInChildren<Animator>();
|
||||
if (anim != null && anim.GetBool("IsMoving")) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void HandlePlayerChaseAndAttack()
|
||||
{
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
@@ -124,6 +172,24 @@ public class BlindMutantAI : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
// Если игрок замер на месте и не издает звуков — слепой мутант не может его заметить и атаковать!
|
||||
if (IsPlayerSilentAndStill())
|
||||
{
|
||||
agent.isStopped = true;
|
||||
silentPlayerTimer += Time.deltaTime;
|
||||
|
||||
// Если игрок сохраняет тишину и неподвижность 0.8 секунды — мутант теряет цель и возвращается к патрулю
|
||||
if (silentPlayerTimer >= 0.8f)
|
||||
{
|
||||
LosePlayerTarget();
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
silentPlayerTimer = 0f;
|
||||
}
|
||||
|
||||
float distanceToPlayer = Vector3.Distance(transform.position, targetPlayer.position);
|
||||
|
||||
// Игрок убежал слишком далеко
|
||||
@@ -174,6 +240,9 @@ public class BlindMutantAI : MonoBehaviour
|
||||
{
|
||||
if (targetPlayerHealth == null || targetPlayerHealth.IsDead) return;
|
||||
|
||||
// Если игрок стоит на месте и не издает звуков (нет волн эхолокации в шейдере) — слепой мутант его не замечает!
|
||||
if (IsPlayerSilentAndStill()) return;
|
||||
|
||||
float distance = Vector3.Distance(transform.position, targetPlayerHealth.transform.position);
|
||||
if (distance <= detectionRadius)
|
||||
{
|
||||
@@ -185,11 +254,25 @@ public class BlindMutantAI : MonoBehaviour
|
||||
{
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
|
||||
if (!agent.pathPending && agent.remainingDistance < 0.6f)
|
||||
if (isInvestigating)
|
||||
{
|
||||
investigationTimer += Time.deltaTime;
|
||||
// Защита от застревания: если не дошел до точки звука за 10 сек, возвращаемся к патрулю
|
||||
if (investigationTimer >= 10f)
|
||||
{
|
||||
isInvestigating = false;
|
||||
investigationTimer = 0f;
|
||||
agent.speed = walkSpeed;
|
||||
waitTimer = waitTimeAtPoint;
|
||||
}
|
||||
}
|
||||
|
||||
if (!agent.pathPending && (agent.remainingDistance < 0.8f || !agent.hasPath))
|
||||
{
|
||||
if (isInvestigating)
|
||||
{
|
||||
isInvestigating = false;
|
||||
investigationTimer = 0f;
|
||||
agent.speed = walkSpeed;
|
||||
waitTimer = waitTimeAtPoint;
|
||||
}
|
||||
@@ -228,6 +311,7 @@ public class BlindMutantAI : MonoBehaviour
|
||||
private void LosePlayerTarget()
|
||||
{
|
||||
targetPlayer = null;
|
||||
silentPlayerTimer = 0f;
|
||||
if (agent != null && agent.isOnNavMesh)
|
||||
{
|
||||
agent.isStopped = false;
|
||||
@@ -237,7 +321,7 @@ public class BlindMutantAI : MonoBehaviour
|
||||
waitTimer = 0f;
|
||||
|
||||
GoToNextPatrolPoint();
|
||||
Debug.Log("Мутант потерял игрока и возвращается к патрулированию.");
|
||||
Debug.Log("Мутант потерял игрока (игрок замер в тишине) и возвращается к патрулированию.");
|
||||
}
|
||||
|
||||
private void GoToNextPatrolPoint()
|
||||
@@ -290,6 +374,7 @@ public class BlindMutantAI : MonoBehaviour
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
|
||||
isInvestigating = true;
|
||||
investigationTimer = 0f;
|
||||
waitTimer = 0f;
|
||||
agent.isStopped = false;
|
||||
agent.speed = runSpeed;
|
||||
@@ -302,6 +387,7 @@ public class BlindMutantAI : MonoBehaviour
|
||||
{
|
||||
animator.SetTrigger("GetHit");
|
||||
}
|
||||
silentPlayerTimer = 0f;
|
||||
EngagePlayer(player);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user