Files
MovementTests/scenes/enemies/Explosion.cs
Minimata 916a6e7153
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 33s
Create tag and build when new code gets to main / Test (push) Successful in 6m19s
Create tag and build when new code gets to main / Export (push) Successful in 7m39s
some editor icons and a base level scene
2026-01-27 10:35:35 +01:00

37 lines
1.1 KiB
C#

using Godot;
using System;
using Movementtests.interfaces;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_projectile.png")]
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();
}
}