homing projectiles
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user