implemented player health, knockback, invicibility frames and hitstop
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 20s
Create tag and build when new code gets to main / Export (push) Successful in 9m56s

This commit is contained in:
2026-01-20 12:05:31 +01:00
parent 87a9fad005
commit 2e5fcb6a75
10 changed files with 206 additions and 39 deletions

View File

@@ -73,7 +73,6 @@ public partial class Enemy : CharacterBody3D,
public void SetupSignals()
{
_damageBox.BodyEntered += OnDamageBoxTriggered;
if (CDamage is IDamageable damageable)
{
damageable.DamageTaken += ReduceHealth;
@@ -84,6 +83,9 @@ public partial class Enemy : CharacterBody3D,
public override void _PhysicsProcess(double delta)
{
// Only trigger gameplay related effects 4 times per second
if(Engine.GetPhysicsFrames() % 15 == 0) ProcessGameplay(delta);
var targetPlanar = new Vector3(Target.GlobalPosition.X, GlobalPosition.Y, Target.GlobalPosition.Z);
LookAt(targetPlanar);
@@ -98,6 +100,16 @@ public partial class Enemy : CharacterBody3D,
Velocity += ComputeKnockback();
MoveAndSlide();
}
public void ProcessGameplay(double delta)
{
var bodies = _damageBox.GetOverlappingBodies();
foreach (var body in bodies)
{
if(body is IDamageable spawnable)
spawnable.TakeDamage(new DamageRecord(this, RDamage));
}
}
public Vector3 ComputeVelocity(MovementInputs inputs)
{
@@ -105,14 +117,6 @@ public partial class Enemy : CharacterBody3D,
return movement!.ComputeVelocity(inputs);
}
public void OnDamageBoxTriggered(Node3D body)
{
if (body is not IDamageable damageable) return;
var damageRecord = new DamageRecord(this, RDamage);
damageable.TakeDamage(damageRecord);
}
public DamageRecord TakeDamage(DamageRecord damageRecord)
{
if (CDamage is not IDamageable damageable)
@@ -120,8 +124,6 @@ public partial class Enemy : CharacterBody3D,
var finalDamage = damageable.TakeDamage(damageRecord);
DamageTaken?.Invoke(this, finalDamage);
GD.Print($"Received damage: {finalDamage.Damage.DamageDealt}");
return finalDamage;
}
@@ -129,6 +131,7 @@ public partial class Enemy : CharacterBody3D,
{
if (CHealth is not IHealthable healthable) return;
healthable.ReduceHealth(source, damageRecord);
HealthChanged?.Invoke(this, healthable.CurrentHealth);
}
public void Kill(IHealthable source)