Big fix patch for enemy behaviors
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user