Refactor projectiles

This commit is contained in:
2023-09-06 15:20:34 -07:00
parent d536aa2014
commit d7dd58b5df
11 changed files with 138 additions and 181 deletions

View File

@@ -1,16 +1,21 @@
using Godot;
using Godot.Collections;
using System.Linq;
public partial class Projectile : Node3D
{
[Export]
public double Cooldown { get; protected set; }
[Export]
protected float _projectileSpeed = 1f;
[Export]
public AudioStream _soundEffect;
public Character ParentCharacter;
[Export]
protected float _projectileSpeed = 1f;
private Array<Path3D> _paths;
public override void _Ready()
{
@@ -18,12 +23,19 @@ public partial class Projectile : Node3D
var sfxPlayer = GetTree().Root.GetNode<AudioStreamPlayer>("Main/SFXPlayer");
sfxPlayer.Stream = _soundEffect;
sfxPlayer.Play();
_paths = new Array<Path3D>(GetChildren().OfType<Path3D>());
}
public override void _PhysicsProcess(double delta)
{
foreach (var paths in _paths)
{
var pathFollow = paths.GetChildren().OfType<PathFollow3D>().Single();
pathFollow.Progress += Speed * (float)delta;
if (pathFollow.ProgressRatio > 0.9f)
QueueFree();
}
}
public float Speed { get; private set; }
public void OnTimeToLiveTimeout()
{
QueueFree();
}
}