FEATURE: Player is falling down at death
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

- Теперь игрок при смерти будет падать вниз
- Изменил поведение игрока при смерти
- Изменил поведение врагов при смерти игрока
- Изменил поведение ловушек при смерти игрока
This commit is contained in:
Данил Ярош 2026-01-26 14:52:36 +03:00
parent e929afd2c4
commit e98d4a4ae4
8 changed files with 104 additions and 33 deletions

File diff suppressed because one or more lines are too long

View File

@ -233655,9 +233655,9 @@ GameObject:
- component: {fileID: 2526968638211351719}
- component: {fileID: 1976856885447583952}
- component: {fileID: 7905545984491440592}
m_Layer: 0
m_Layer: 6
m_Name: Box
m_TagString: Trap
m_TagString: Ground
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

View File

@ -26,6 +26,7 @@ namespace RR.Game2D.Animations
// Components
private Rigidbody2D _rb;
private Collider2D _col;
private PlayerController _controller;
// VFX Spawn Points
private Vector3 _deathVFXSpawnPoint;
@ -37,7 +38,7 @@ namespace RR.Game2D.Animations
private void Awake()
{
PlayerController controller = GetComponent<PlayerController>();
_controller = GetComponent<PlayerController>();
UpdateSFX();
@ -68,6 +69,9 @@ namespace RR.Game2D.Animations
PlayerFireScript fireScript = GetComponent<PlayerFireScript>();
if (fireScript.enableFire) fireScript.enableFire = false;
if (!_rb) _rb = GetComponent<Rigidbody2D>();
_rb.linearVelocity = Vector2.zero;
}
public void OnDeathEnd()
@ -79,7 +83,8 @@ namespace RR.Game2D.Animations
if (deathVFX) VFXPool.Instance.Spawn(deathVFX, _deathVFXSpawnPoint, 1f);
gameObject.layer = LayerMask.NameToLayer("Default");
_rb.constraints = RigidbodyConstraints2D.FreezeRotation;
// _rb.constraints = RigidbodyConstraints2D.FreezeRotation;
_controller.isDeadAtMoment = false;
PlayerFireScript fireScript = GetComponent<PlayerFireScript>();
if (!fireScript.enableFire) fireScript.enableFire = true;

View File

@ -54,12 +54,14 @@ namespace RR.Game2D.Behaviour
private void FixedUpdate()
{
if (!_playerObj) return;
// if (rb.linearVelocity.x > 0.0001f) Debug.Log(rb.linearVelocity.x);
_playerObj.TryGetComponent(out PlayerController playerController);
Vector3 playerCenter = _playerObj.transform.position;
if (PlayerInSight())
if (PlayerInSight() && !playerController.isDeadAtMoment)
{
Vector3 toPlayer = playerCenter - transform.position;
float dist = toPlayer.magnitude + 0.1f;
@ -89,6 +91,9 @@ namespace RR.Game2D.Behaviour
_playerObj.TryGetComponent(out PlayerController playerController);
if (playerRb == null) return;
Vector2 contactNormal = collision.GetContact(0).normal;
if (playerController.isDeadAtMoment) return;
if (contactNormal.y < -0.5f)
{
playerRb.linearVelocity = new Vector2(playerRb.linearVelocity.x, 35f);

View File

@ -54,14 +54,19 @@ namespace RR.Game2D.Behaviour
[SerializeField] public SFXAsset hurtSounds;
[SerializeField] public SFXAsset jumpSounds;
private Rigidbody2D rb;
// private Collider2D col;
[HideInInspector] public bool isDeadAtMoment;
private Rigidbody2D rb;
// Ввод
private float _inputX;
private bool _jumpPressed, _jumpReleased, _jumpHold;
// Порог скорости падения для смены демпфирования камеры
private float _fallSpeedYDampingChangeThreshold;
// Состояние смерти
// Антизастревание
private float _stuckTime;
private float _unstuckCooldownTimer;
@ -143,6 +148,8 @@ namespace RR.Game2D.Behaviour
private void FixedUpdate()
{
if (isDeadAtMoment) return;
animator.SetBool(Jump, false);
// Горизонтальное движение
@ -200,8 +207,9 @@ namespace RR.Game2D.Behaviour
public void Die()
{
gameObject.layer = LayerMask.NameToLayer("No Collision");
rb.constraints = RigidbodyConstraints2D.FreezeAll;
gameObject.layer = LayerMask.NameToLayer("No Enemy Collision");
// rb.constraints = RigidbodyConstraints2D.FreezeAll;
isDeadAtMoment = true;
animator.SetTrigger(Death);
}

View File

@ -20,7 +20,9 @@ namespace RR.Game2D.Entities.Hazards
{
if (collision.collider.TryGetComponent<PlayerController>(out var controller))
controller.Die();
{
if (!controller.isDeadAtMoment) controller.Die();
}
}
else if (collision.collider.CompareTag("Enemy"))
{

View File

@ -3,7 +3,7 @@
--- !u!19 &1
Physics2DSettings:
m_ObjectHideFlags: 0
serializedVersion: 6
serializedVersion: 11
m_Gravity: {x: 0, y: -9.81}
m_DefaultMaterial: {fileID: 0}
m_VelocityIterations: 8
@ -53,4 +53,5 @@ Physics2DSettings:
m_ReuseCollisionCallbacks: 1
m_AutoSyncTransforms: 0
m_GizmoOptions: 10
m_LayerCollisionMatrix: f7fffffff7fffffff7ffffffc0fffffff7fffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: f7fefffff7fffffff7ffffffc0fffffff7fffffff7fffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_PhysicsLowLevelSettings: {fileID: 0}

View File

@ -20,7 +20,7 @@ TagManager:
- UI
- Ground
- Light
-
- No Enemy Collision
-
-
-