если выйти из врага он будет жив. есть переход на следующий этаж
This commit is contained in:
1 parent
263af0a52e
commit
ccaf43b3fe
10 files changed
+587
-68
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Scripts.PlayerUtils
|
||||
{
|
||||
@@ -17,20 +18,23 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
public float CurrentHealth { get; private set; }
|
||||
public bool IsDead { get; private set; }
|
||||
public bool IsPossessed { get; private set; }
|
||||
|
||||
// Можно вселяться в любого живого врага (или если у него осталось мало ХП — на твой выбор)
|
||||
public bool CanBePossessed => !IsDead;
|
||||
public bool CanBePossessed => !IsDead && !IsPossessed;
|
||||
|
||||
private Rigidbody _rb;
|
||||
private Collider _col;
|
||||
private Transform _playerTransform;
|
||||
private float _fireTimer;
|
||||
private float _strafeTimer;
|
||||
private float _stunTimer; // Оглушение после того, как Дух покинул тело
|
||||
private int _strafeDir = 1;
|
||||
private LineRenderer _sniperLaser;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_rb = GetComponent<Rigidbody>();
|
||||
_col = GetComponent<Collider>();
|
||||
_rb.freezeRotation = true;
|
||||
}
|
||||
|
||||
@@ -44,7 +48,8 @@ namespace _Project.Scripts.PlayerUtils
|
||||
profile = BodyProfile.CreateDefault(enemyClass);
|
||||
}
|
||||
|
||||
CurrentHealth = profile.maxHealth;
|
||||
if (CurrentHealth <= 0f)
|
||||
CurrentHealth = profile.maxHealth;
|
||||
|
||||
if (enemyClass == BodyClass.Sniper && _sniperLaser == null)
|
||||
{
|
||||
@@ -52,6 +57,53 @@ namespace _Project.Scripts.PlayerUtils
|
||||
}
|
||||
}
|
||||
|
||||
// Вызывается, когда Дух игрока захватывает это тело
|
||||
public void OnPossessedByPlayer()
|
||||
{
|
||||
IsPossessed = true;
|
||||
if (_sniperLaser != null) _sniperLaser.enabled = false;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Вызывается, когда Дух покидает это тело, пока оно ещё живо!
|
||||
public void OnReleasedFromPossession(Vector3 releasePos, Quaternion releaseRot, float remainingHealth, float stunTime = 0.8f)
|
||||
{
|
||||
IsPossessed = false;
|
||||
CurrentHealth = Mathf.Max(1f, remainingHealth);
|
||||
|
||||
transform.SetPositionAndRotation(releasePos, releaseRot);
|
||||
gameObject.SetActive(true);
|
||||
|
||||
_stunTimer = stunTime;
|
||||
_fireTimer = Mathf.Max(_fireTimer, stunTime + 0.3f);
|
||||
|
||||
if (_rb != null)
|
||||
{
|
||||
_rb.linearVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
// Временно отключаем физическое столкновение с капсулой игрока на 0.6 сек,
|
||||
// чтобы при выпрыгивании из тела игрок и враг не застряли друг в друге!
|
||||
if (_col != null && Player.Instance != null)
|
||||
{
|
||||
var playerCol = Player.Instance.GetComponent<Collider>();
|
||||
if (playerCol != null)
|
||||
{
|
||||
StartCoroutine(TemporaryIgnorePlayerCollision(playerCol, 0.6f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator TemporaryIgnorePlayerCollision(Collider playerCol, float duration)
|
||||
{
|
||||
Physics.IgnoreCollision(_col, playerCol, true);
|
||||
yield return new WaitForSecondsRealtime(duration);
|
||||
if (_col != null && playerCol != null)
|
||||
{
|
||||
Physics.IgnoreCollision(_col, playerCol, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupSniperLaser()
|
||||
{
|
||||
_sniperLaser = gameObject.AddComponent<LineRenderer>();
|
||||
@@ -65,7 +117,15 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (IsDead || _playerTransform == null) return;
|
||||
if (IsDead || IsPossessed || _playerTransform == null) return;
|
||||
|
||||
// Пока враг приходит в себя после изгнания духа — он не стреляет
|
||||
if (_stunTimer > 0f)
|
||||
{
|
||||
_stunTimer -= Time.deltaTime;
|
||||
if (_sniperLaser != null) _sniperLaser.enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_fireTimer -= Time.deltaTime;
|
||||
_strafeTimer -= Time.deltaTime;
|
||||
@@ -86,7 +146,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
return;
|
||||
}
|
||||
|
||||
// Поворот лицом к игроку по горизонтали
|
||||
Vector3 flatDir = new Vector3(toPlayer.x, 0f, toPlayer.z).normalized;
|
||||
if (flatDir.sqrMagnitude > 0.001f)
|
||||
{
|
||||
@@ -94,7 +153,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
transform.rotation, Quaternion.LookRotation(flatDir), Time.deltaTime * 10f);
|
||||
}
|
||||
|
||||
// Лазер снайпера виден за 0.5 сек до выстрела
|
||||
if (_sniperLaser != null)
|
||||
{
|
||||
_sniperLaser.enabled = _fireTimer < 0.5f;
|
||||
@@ -105,7 +163,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
}
|
||||
}
|
||||
|
||||
// Стрельба по игроку
|
||||
if (dist <= profile.weaponRange && _fireTimer <= 0f)
|
||||
{
|
||||
ShootAtPlayer(eyePos, toPlayer.normalized);
|
||||
@@ -114,7 +171,13 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (IsDead || _playerTransform == null) return;
|
||||
if (IsDead || IsPossessed || _playerTransform == null) return;
|
||||
|
||||
if (_stunTimer > 0f)
|
||||
{
|
||||
_rb.linearVelocity = new Vector3(0f, _rb.linearVelocity.y, 0f);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 eyePos = transform.position + Vector3.up * eyeHeight;
|
||||
Vector3 targetPos = _playerTransform.position + Vector3.up * 1.0f;
|
||||
@@ -131,17 +194,14 @@ namespace _Project.Scripts.PlayerUtils
|
||||
Vector3 right = Vector3.Cross(Vector3.up, forward);
|
||||
Vector3 moveDir = Vector3.zero;
|
||||
|
||||
// Тактика передвижения зависит от класса!
|
||||
switch (enemyClass)
|
||||
{
|
||||
case BodyClass.Scout:
|
||||
// Агрессивно сближается зигзагами
|
||||
if (dist > 3.5f) moveDir = (forward + right * (_strafeDir * 0.65f)).normalized;
|
||||
else moveDir = right * _strafeDir;
|
||||
break;
|
||||
|
||||
case BodyClass.Trooper:
|
||||
// Держит среднюю дистанцию (8-14м) и стрейфит
|
||||
if (dist > 14f) moveDir = forward + right * (_strafeDir * 0.3f);
|
||||
else if (dist < 7f) moveDir = -forward + right * (_strafeDir * 0.5f);
|
||||
else moveDir = right * _strafeDir;
|
||||
@@ -149,12 +209,10 @@ namespace _Project.Scripts.PlayerUtils
|
||||
break;
|
||||
|
||||
case BodyClass.Juggernaut:
|
||||
// Медленно и неотвратимо идёт напролом
|
||||
if (dist > 4f) moveDir = forward;
|
||||
break;
|
||||
|
||||
case BodyClass.Sniper:
|
||||
// Держится далеко (отступает, если игрок ближе 15м)
|
||||
if (dist < 15f) moveDir = -forward + right * (_strafeDir * 0.25f);
|
||||
else if (dist > 28f) moveDir = forward;
|
||||
moveDir.Normalize();
|
||||
@@ -183,8 +241,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
int pellets = Mathf.Max(1, profile.pelletsPerShot);
|
||||
float spread = Mathf.Max(1.5f, profile.spreadAngle + 1.5f);
|
||||
|
||||
// Сдвигаем точку вылета чуть вперёд от глаз врага
|
||||
Vector3 muzzlePos = origin + baseDir * 0.6f;
|
||||
|
||||
for (int i = 0; i < pellets; i++)
|
||||
|
||||
Reference in new issue
Block a user