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