homing projectiles

This commit is contained in:
2026-05-10 12:26:43 +02:00
parent 150e007b22
commit 0cd942d90e
5 changed files with 54 additions and 11 deletions

View File

@@ -12,14 +12,24 @@ public class SpawnProjectileBehavior(PackedScene projectileScene) : IAbilityBeha
{
public void OnStarted(AbilityBehaviorContext context)
{
if (context.Target is not Node3D target || context.Source is not Node3D source) return;
if (context.Target is not Node3D target || context.Source is not Node3D source)
{
context.InstanceHandle.End();
return;
}
var sourceLocation = source.GlobalPosition;
if (projectileScene.Instantiate() is not Projectile projectile) return;
if (projectileScene.Instantiate() is not Projectile projectile)
{
context.InstanceHandle.End();
return;
}
source.GetTree().GetCurrentScene().AddChild(projectile);
projectile.GlobalPosition = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : sourceLocation;
var startPos = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : sourceLocation;
projectile.GlobalPosition = startPos + Vector3.Up;
projectile.Target = target;
if (projectile is ISpawnable spawnable) spawnable.Init();