Add AI components and systems for enhanced enemy behavior and pathfinding

This commit is contained in:
2025-10-30 21:53:20 +01:00
parent f65277e6b4
commit c7739de7d9
11 changed files with 370 additions and 6 deletions

View File

@@ -8,14 +8,17 @@ public class GravitySystem : ISystem
{
public void Update(World world, float deltaTime)
{
var entities = world.GetEntitiesWith<VelocityComponent>();
var entities = world.GetEntitiesWith<CharacterStateComponent>();
foreach (var entity in entities)
{
var velocity = world.GetComponent<VelocityComponent>(entity);
var characterState = world.GetComponent<CharacterStateComponent>(entity);
if (velocity == null || characterState == null)
{
world.Logger.Warn("GravitySystem: Missing VelocityComponent or CharacterStateComponent.");
continue;
}
if (!characterState.IsOnFloor) velocity.DesiredVelocity.Y -= world.Config.GravityStrength * deltaTime;
}

View File

@@ -1,6 +1,7 @@
using GameCore.ECS;
using GameCore.ECS.Interfaces;
using GameCore.Input;
using GameCore.Player;
namespace GameCore.Movement;
@@ -18,10 +19,28 @@ public class RotationSystem : ISystem
var rotation = world.GetComponent<RotationComponent>(entity);
if (input == null || rotation == null)
{
world.Logger.Warn("RotationSystem: Missing InputStateComponent or RotationComponent.");
continue;
}
if (world.GetComponent<PlayerComponent>(entity) != null)
{
rotation.Rotation.Y += input.LookDirection.Y;
rotation.Rotation.X += input.LookDirection.X;
}
else
{
if (input.LookDirection.Length() > 0.001f)
{
var lookDir = input.LookDirection;
rotation.Rotation.Y = (float)System.Math.Atan2(lookDir.X, lookDir.Z);
var horizontalDist = (float)System.Math.Sqrt(lookDir.X * lookDir.X + lookDir.Z * lookDir.Z);
rotation.Rotation.X = -(float)System.Math.Atan2(lookDir.Y, horizontalDist);
}
}
rotation.Rotation.Y += input.LookDirection.Y;
rotation.Rotation.X += input.LookDirection.X;
rotation.Rotation.X = System.Math.Clamp(rotation.Rotation.X, MinPitch, MaxPitch);
}