Implement player punch and crude damage system

This commit is contained in:
RochesterX
2025-01-17 19:46:17 -05:00
parent 0824f3c99a
commit 7a646ca1ea
10 changed files with 1646 additions and 240 deletions

View File

@@ -0,0 +1,35 @@
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
[RequireComponent(typeof(Collider2D))]
[RequireComponent(typeof(RespawnOnTriggerEnter))]
public class Damageable : MonoBehaviour
{
public float force = 50f;
public float damage = 0f;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Punch Hurtbox"))
{
print($"{name}: Ouch");
Damage();
Recoil(collision.transform.parent.gameObject);
}
}
private void Recoil(GameObject damageSource)
{
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up) * damage, ForceMode2D.Force);
}
private void Damage()
{
damage += force;
}
public void ResetDamage()
{
damage = 0f;
}
}