Add death animation

This commit is contained in:
RochesterX
2025-03-07 10:46:30 -05:00
parent 6528d1050f
commit c36f3b5a1a
8 changed files with 4000 additions and 230 deletions

View File

@@ -14,12 +14,25 @@ public class Damageable : MonoBehaviour
//private GameManager gameManager;
private Animator animator;
public bool damageSelfDebug = false;
public bool dying = false;
private void Start()
{
//gameManager = GameManager.Instance;
animator = GetComponent<Animator>();
}
private void Update()
{
if (damageSelfDebug)
{
damageSelfDebug = false;
Damage(gameObject);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Punch Hurtbox"))
@@ -31,7 +44,7 @@ public class Damageable : MonoBehaviour
private void Damage(GameObject damageSource)
{
float actualForce = force;
float actualForce = damageSource.GetComponent<Damageable>().force;
Block blockComponent = GetComponent<Block>();
if (blockComponent != null && blockComponent.blocking)
{
@@ -48,7 +61,7 @@ public class Damageable : MonoBehaviour
}
else
{
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up * 2) * actualForce, ForceMode2D.Force);
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up * 2) * actualForce * (1 + (damage / maxDamage) * 3), ForceMode2D.Force);
}
damage += actualForce;
damage = Mathf.Clamp(damage, 0f, maxDamage);
@@ -83,16 +96,16 @@ public class Damageable : MonoBehaviour
//Debug.Log($"{name}: MAKE THIS WORK.");
if (GameManager.Instance != null)
{
animator.SetTrigger("Die");
StartCoroutine(HandleDeath());
animator.SetTrigger("die");
dying = true;
//StartCoroutine(HandleDeath()); // Handled by an animation event instead.
}
}
private IEnumerator HandleDeath()
public void HandleDeath()
{
//yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);
yield return new WaitForSeconds(0.5f);
GameManager.Instance.PlayerDied(this);
dying = false;
}
public void Respawn()

View File

@@ -36,6 +36,7 @@ public class PlayerCameraMovement : MonoBehaviour
Vector3 playerAverage = Vector3.zero;
foreach (GameObject player in players)
{
if (player.GetComponent<Damageable>().dying) continue;
playerAverage += player.transform.position;
}
playerAverage /= players.Count;

View File

@@ -1,9 +1,7 @@
using System.Collections;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Tilemaps;
[RequireComponent(typeof(Rigidbody2D))]
[RequireComponent(typeof(BoxCollider2D))]
@@ -40,6 +38,7 @@ public class PlayerMovement : MonoBehaviour
private PlayerInput input;
private AnimationPlayer animationPlayer;
private Punch punch;
private Damageable damageable;
private bool jumpInputStillValid = false;
private float lastTimeJumpPressed;
@@ -64,12 +63,15 @@ public class PlayerMovement : MonoBehaviour
input = GetComponent<PlayerInput>();
animationPlayer = GetComponent<AnimationPlayer>();
punch = GetComponent<Punch>();
damageable = GetComponent<Damageable>();
playerText.text = input.playerIndex.ToString();
}
private void Update()
{
if (damageable.dying) return;
Jump();
UpdateVirtualAxis();