instanciating explosion on slam
Some checks failed
Create tag and build when new code gets to main / BumpTag (push) Has been cancelled
Create tag and build when new code gets to main / Test (push) Has been cancelled
Create tag and build when new code gets to main / Export (push) Has been cancelled

This commit is contained in:
2026-01-26 16:34:18 +01:00
parent d79ca44972
commit 2fdc9c7ca8
13 changed files with 122 additions and 32 deletions

View File

@@ -0,0 +1,36 @@
using Godot;
using System;
using Movementtests.interfaces;
[GlobalClass]
public partial class Explosion : Area3D, IDamageDealer
{
[Export] public RDamage RDamage { get; set;}
[Export] public float Radius { get; set;}
[Export] public float ExplosionTime { get; set; } = 0.2f;
public override void _Ready()
{
var sphereShape = GetNode<CollisionShape3D>("CollisionShape3D").Shape as SphereShape3D;
sphereShape!.Radius = Radius;
var sphereMesh = GetNode<MeshInstance3D>("MeshInstance3D").Mesh as SphereMesh;
sphereMesh!.Radius = Radius;
sphereMesh!.Height = Radius*2f;
GetTree().CreateTimer(ExplosionTime).Timeout += TriggerExplosion;
}
public void TriggerExplosion()
{
var bodies = GetOverlappingBodies();
foreach (var body in bodies)
{
if (body is IDamageable damageable)
damageable.TakeDamage(new DamageRecord(GlobalPosition, RDamage));
if (body is IStunnable stunnable)
stunnable.Stun();
}
QueueFree();
}
}