Enemy follow system

This commit is contained in:
2024-09-03 00:41:15 -07:00
parent dc9d9c4589
commit 8df3abc775
11 changed files with 156 additions and 56 deletions

View File

@@ -15,6 +15,19 @@ namespace GameJamDungeon
var delta = input.Delta;
var gameRepo = Get<IGameRepo>();
var enemy = Get<IEnemy>();
if (enemy.GlobalPosition.DistanceTo(gameRepo.PlayerGlobalPosition.Value) <= 2.5f)
{
enemy.LookAt(new Vector3(gameRepo.PlayerGlobalPosition.Value.X, enemy.GlobalPosition.Y, gameRepo.PlayerGlobalPosition.Value.Z), Vector3.Up);
return ToSelf();
}
enemy.NavAgent.TargetPosition = gameRepo.PlayerGlobalPosition.Value;
var nextPosition = enemy.NavAgent.GetNextPathPosition();
enemy.LookAt(enemy.NavAgent.GetNextPathPosition());
var direction = enemy.NavAgent.GetNextPathPosition() - enemy.GlobalPosition;
enemy.Velocity = direction * 2.0f * (float)delta;
Output(new Output.MovementComputed(enemy.Velocity));
return ToSelf();