Big fix patch for enemy behaviors

This commit is contained in:
2025-10-29 00:35:15 -07:00
parent 1a77695155
commit 21d8c4770d
57 changed files with 904 additions and 1373 deletions

View File

@@ -6,6 +6,7 @@ using System.Collections.Immutable;
using System.Linq;
using Zennysoft.Ma.Adapter;
using Zennysoft.Ma.Adapter.Entity;
using static Zennysoft.Ma.Adapter.AppLogic;
namespace Zennysoft.Game.Ma;
@@ -45,7 +46,8 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
[Export] public int ExpGiven { get; set; } = 10;
private bool _activated = false;
protected bool _activated = false;
private Vector3 _previousPosition = Vector3.Zero;
public Enemy()
{
@@ -180,9 +182,17 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
protected void LookAtTarget(Vector3 targetPosition)
{
var velocity = GlobalPosition - _previousPosition;
if (velocity.IsZeroApprox())
{
_previousPosition = GlobalPosition;
return;
}
var lookDirection = GlobalPosition - targetPosition;
if (lookDirection != GlobalPosition)
LookAt(new Vector3(lookDirection.X, GlobalPosition.Y, lookDirection.Z), Vector3.Up);
var look = new Vector3(lookDirection.X, GlobalPosition.Y, lookDirection.Z);
if (!look.IsEqualApprox(GlobalPosition))
LookAt(look, Vector3.Up);
}
protected void SetTarget(Vector3 targetPosition) => TargetPosition = targetPosition;