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

@@ -72,6 +72,7 @@ public partial class Projectile : RigidBody3D, IForgeEntity, ITargetable, IKilla
[Export] public float HomingFactor = 0.2f;
public Node3D? Target { get; set; }
public Vector3? ImpulseDirection { get; set; }
public void Init()
{
@@ -80,6 +81,7 @@ public partial class Projectile : RigidBody3D, IForgeEntity, ITargetable, IKilla
public Vector3 ComputeImpulseToTarget()
{
if (ImpulseDirection != null) return ImpulseDirection.Value;
if (Target == null) return Vector3.Zero;
return Vector3.Up * Speed;
@@ -93,6 +95,7 @@ public partial class Projectile : RigidBody3D, IForgeEntity, ITargetable, IKilla
public override void _IntegrateForces(PhysicsDirectBodyState3D state)
{
base._IntegrateForces(state);
if (Target == null) return;
var targetPos = Target is ITargetable targetable ? targetable.GetTargetGlobalPosition() : Target.GlobalPosition;
var targetVel = state.LinearVelocity + GlobalPosition.DirectionTo(targetPos) * HomingFactor;