Random patrol

This commit is contained in:
2024-09-04 18:31:35 -07:00
parent d24b28acd5
commit 6fc9568137
4 changed files with 43 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ public partial class EnemyLogic
public partial record State
{
[Meta, Id("enemy_logic_state_idle")]
public partial record Idle : Alive, IGet<Input.Alerted>, IGet<Input.PhysicsTick>
public partial record Idle : Alive, IGet<Input.Alerted>, IGet<Input.PhysicsTick>, IGet<Input.PatrolToRandomSpot>
{
public Transition On(in Input.Alerted _)
{
@@ -20,6 +20,22 @@ public partial class EnemyLogic
var delta = input.Delta;
var gameRepo = Get<IGameRepo>();
var enemy = Get<IEnemy>();
var nextPosition = enemy.NavAgent.GetNextPathPosition();
var lookAtPos = enemy.NavAgent.GetNextPathPosition();
var direction = enemy.NavAgent.GetNextPathPosition() - enemy.GlobalPosition;
enemy.Velocity = enemy.Velocity.MoveToward(direction.Normalized() * 0.01f, (float)delta);
Output(new Output.MovementComputed(enemy.Velocity));
return ToSelf();
}
public Transition On(in Input.PatrolToRandomSpot input)
{
var enemy = Get<IEnemy>();
enemy.NavAgent.TargetPosition = input.PatrolTarget;
enemy.LookAt(new Vector3(input.PatrolTarget.X, enemy.GlobalPosition.Y, input.PatrolTarget.Z), Vector3.Up);
return ToSelf();
}
}