instanciating explosion on slam
This commit is contained in:
36
scenes/enemies/Explosion.cs
Normal file
36
scenes/enemies/Explosion.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user