Knockback tag implementation
This commit is contained in:
@@ -6,7 +6,7 @@ using Godot;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public interface IEnemy : ICharacterBody3D
|
||||
public interface IEnemy : IRigidBody3D
|
||||
{
|
||||
public IEnemyLogic EnemyLogic { get; }
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface IEnemy : ICharacterBody3D
|
||||
}
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
public partial class Enemy : RigidBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
@@ -69,6 +69,9 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
private const string ATTACK_FORWARD = "attack";
|
||||
|
||||
private float _knockbackStrength = 0.0f;
|
||||
private Vector3 _knockbackDirection = Vector3.Zero;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
EnemyLogic = new EnemyLogic();
|
||||
@@ -128,7 +131,8 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
.Handle((in EnemyLogic.Output.MovementComputed output) =>
|
||||
{
|
||||
RotateEnemy(-GameRepo.PlayerGlobalTransform.Value.Basis.Z);
|
||||
MoveAndSlide();
|
||||
_knockbackStrength = _knockbackStrength * 0.9f;
|
||||
MoveAndCollide(output.LinearVelocity + (_knockbackDirection * _knockbackStrength));
|
||||
})
|
||||
.Handle((in EnemyLogic.Output.HitByPlayer output) =>
|
||||
{
|
||||
@@ -138,6 +142,11 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
// TODO: Make this an event to notify game that player hit someone
|
||||
if (GameRepo.PlayerData.Inventory.EquippedWeapon.Value.WeaponStats.WeaponTags.Contains(WeaponTag.SelfDamage))
|
||||
GameRepo.PlayerData.SetCurrentHP(GameRepo.PlayerData.CurrentHP.Value - 5);
|
||||
if (GameRepo.PlayerData.Inventory.EquippedWeapon.Value.WeaponStats.WeaponTags.Contains(WeaponTag.Knockback))
|
||||
{
|
||||
_knockbackDirection = -GameRepo.PlayerGlobalTransform.Value.Basis.Z.Normalized();
|
||||
_knockbackStrength = 0.3f;
|
||||
}
|
||||
})
|
||||
.Handle((in EnemyLogic.Output.Attack _) =>
|
||||
{
|
||||
@@ -265,9 +274,9 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>().Travel("idle_back_walk");
|
||||
else
|
||||
{
|
||||
// If the dot product of the perpendicular dot product is positive (up to 1), the enemy is facing to the left (since it's mirrored).
|
||||
// If the dot product of the perpendicular direction is positive (up to 1), the enemy is facing to the left (since it's mirrored).
|
||||
AnimatedSprite.FlipH = leftDotProduct > 0;
|
||||
// Check is side facing. If the dot product is close to zero in the positive or negative direction, its close to the threshold for turning.
|
||||
// Check if side facing. If the dot product is close to zero in the positive or negative direction, its close to the threshold for turning.
|
||||
if (Mathf.Abs(forwardDotProduct) < rotateLowerThreshold)
|
||||
AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>().Travel("idle_left_walk");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user