knockback forge implemented
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
namespace Movementtests.scenes.components.knockback;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_wind.png")]
|
||||
public partial class CKnockback : Node3D, IKnockbackable
|
||||
{
|
||||
[Export] public RKnockback RKnockback { get; set;} = null!;
|
||||
|
||||
private KnockbackRecord _knockbackRecord = null!;
|
||||
private KnockbackRecord? _knockbackRecord;
|
||||
|
||||
public void RegisterKnockback(KnockbackRecord knockbackRecord)
|
||||
{
|
||||
@@ -18,9 +19,8 @@ public partial class CKnockback : Node3D, IKnockbackable
|
||||
{
|
||||
if (_knockbackRecord == null) return Vector3.Zero;
|
||||
|
||||
var knockbackDirection = GlobalPosition - _knockbackRecord.DamageRecord.SourceLocation;
|
||||
var finalKnockback = knockbackDirection.Normalized() * RKnockback.Modifier * _knockbackRecord.ForceMultiplier;
|
||||
_knockbackRecord = null!;
|
||||
var finalKnockback = _knockbackRecord.Direction.Normalized() * RKnockback.Modifier * _knockbackRecord.ForceMultiplier;
|
||||
_knockbackRecord = null;
|
||||
return finalKnockback;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
namespace Movementtests.scenes.components.knockback;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_wind.png")]
|
||||
public partial class RKnockback : Resource
|
||||
public partial class RKnockback(float modifier) : Resource
|
||||
{
|
||||
[Export]
|
||||
public float Modifier { get; set;}
|
||||
|
||||
public float Modifier { get; set;} = modifier;
|
||||
|
||||
public RKnockback() : this(1.0f) {}
|
||||
public RKnockback(float modifier)
|
||||
{
|
||||
Modifier = modifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using Gamesmiths.Forge.Statescript;
|
||||
using Gamesmiths.Forge.Tags;
|
||||
using Godot;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.scenes.components.knockback;
|
||||
using Movementtests.systems;
|
||||
using Movementtests.tools;
|
||||
using Movementtests.tools.calculators;
|
||||
@@ -165,9 +166,15 @@ public partial class Enemy : CharacterBody3D,
|
||||
Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.hit"),
|
||||
data => {GD.Print("Hit!");});
|
||||
Events.Subscribe<DamageDone>(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived);
|
||||
Events.Subscribe<KnockbackDone>(Tag.RequestTag(TagsManager, "events.combat.knockback_received"), OnKnockbackReceived);
|
||||
Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.death"), OnDeath);
|
||||
}
|
||||
|
||||
public void OnKnockbackReceived(EventData<KnockbackDone> data)
|
||||
{
|
||||
RegisterKnockback(new KnockbackRecord(data.Payload.knockbackDirection, data.EventMagnitude));
|
||||
}
|
||||
|
||||
public void SetupSignals()
|
||||
{
|
||||
// Anonymous function call to erase return values of ReduceHealth
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_yq03x")
|
||||
Modifier = 20.0
|
||||
Modifier = 2.0
|
||||
metadata/_custom_type_script = "uid://b44cse62qru7j"
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_vdia8")
|
||||
Modifier = 30.0
|
||||
Modifier = 1.0
|
||||
metadata/_custom_type_script = "uid://b44cse62qru7j"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_hsy8g")
|
||||
Speed = 5.0
|
||||
Acceleration = 3.0
|
||||
Speed = 4.0
|
||||
Acceleration = 1.0
|
||||
GravityModifier = 5.0
|
||||
metadata/_custom_type_script = "uid://dtpxijlnb2c5"
|
||||
|
||||
@@ -26,6 +26,7 @@ using Movementtests.interfaces;
|
||||
using Movementtests.systems;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
using Movementtests.managers;
|
||||
using Movementtests.scenes.components.knockback;
|
||||
using Movementtests.tools;
|
||||
using Movementtests.tools.calculators;
|
||||
using RustyOptions;
|
||||
@@ -150,7 +151,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
public float AimAssistReductionStartDistance { get; set; } = 10f;
|
||||
|
||||
[ExportGroup("Damage")] [Export] public RDamage RDamage { get; set; } = null!;
|
||||
[Export] public RKnockback? RKnockback { get; set; } = null!;
|
||||
[Export] public RKnockback? RKnockback { get; set; }
|
||||
|
||||
[ExportGroup("Targeting")]
|
||||
[Export(PropertyHint.Range, "0,20,0.1,or_greater")]
|
||||
@@ -2555,7 +2556,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
|
||||
public void ManualKnockback()
|
||||
{
|
||||
Velocity = -_dashDirection*RKnockback.Modifier;
|
||||
Velocity = -_dashDirection*RKnockback!.Modifier;
|
||||
}
|
||||
|
||||
public static Vector3 ComputePositionAfterTargetedDash(Vector3 targetLocation, Vector3 targetHitLocation)
|
||||
@@ -2625,14 +2626,13 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
if (_hitAbilityHandle is null) return;
|
||||
|
||||
if (!_hitAbilityHandle.CanActivate(out _)) return;
|
||||
|
||||
|
||||
foreach (var entity in _hitEnemies)
|
||||
{
|
||||
// TODO: WTF why doesn't health move
|
||||
// GD.Print(entity.Attributes["EnemyAttributeSet.Health"].CurrentValue);
|
||||
_hitAbilityHandle.Activate(out _, entity);
|
||||
_hitAbilityHandle.Activate(out var flags, entity);
|
||||
}
|
||||
_hitEnemies.Clear();
|
||||
_hitAbilityHandle.Cancel();
|
||||
|
||||
HeadSystem.OnHitTarget();
|
||||
_audioStream.SwitchToClipByName("hits");
|
||||
|
||||
Reference in New Issue
Block a user