parrying projectiles
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 28s
Create tag and build when new code gets to main / Export (push) Successful in 6m44s

This commit is contained in:
2026-05-14 16:11:22 +02:00
parent 0cd942d90e
commit a0e99a959f
11 changed files with 166 additions and 81 deletions

View File

@@ -1,36 +1,44 @@
using Gamesmiths.Forge.Abilities;
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Effects;
using Gamesmiths.Forge.Godot.Resources;
using Gamesmiths.Forge.Godot.Resources.Abilities;
using Godot;
using Movementtests.interfaces;
using Movementtests.tools;
namespace Movementtests.forge.abilities;
public record OnProjectileSpawned(Vector3 Direction, float SpeedMultiplier, Vector3? SpawnOffset = null, uint? CollisionOverride = null);
public class SpawnProjectileBehavior(PackedScene projectileScene) : IAbilityBehavior
public class SpawnProjectileBehavior(PackedScene projectileScene) : IAbilityBehavior<OnProjectileSpawned>
{
public void OnStarted(AbilityBehaviorContext context)
public void OnStarted(AbilityBehaviorContext context, OnProjectileSpawned data)
{
if (context.Target is not Node3D target || context.Source is not Node3D source)
if (context.Source is not Node3D source || projectileScene.Instantiate() is not Projectile projectile)
{
context.InstanceHandle.End();
return;
}
var sourceLocation = source.GlobalPosition;
if (projectileScene.Instantiate() is not Projectile projectile)
{
context.InstanceHandle.End();
return;
}
source.GetTree().GetCurrentScene().AddChild(projectile);
var startPos = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : sourceLocation;
projectile.GlobalPosition = startPos + Vector3.Up;
source.GetTree().GetCurrentScene().AddChild(projectile);
// Computing projectile properties
var offset = data.SpawnOffset ?? Vector3.Zero;
var startPos = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : source.GlobalPosition;
var target = context.Target as Node3D;
var magnitude = context.Magnitude != 0 ? context.Magnitude : 1;
var impulse = data.Direction * data.SpeedMultiplier * magnitude;
var collisionOverride = data.CollisionOverride ?? projectile.CollisionMask;
GD.Print(impulse);
// Setting up projectile
projectile.GlobalPosition = startPos + offset;
projectile.Target = target;
projectile.ImpulseDirection = impulse;
projectile.CollisionMask = collisionOverride;
if (projectile is ISpawnable spawnable) spawnable.Init();
context.AbilityHandle.CommitAbility();