Random patrol
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user