Refactor Enemy
This commit is contained in:
@@ -10,6 +10,7 @@ public partial class EnemyLogic
|
||||
[Meta, Id("enemy_logic_state_idle")]
|
||||
public partial record Idle : Alive, IGet<Input.Alerted>, IGet<Input.PhysicsTick>, IGet<Input.PatrolToRandomSpot>
|
||||
{
|
||||
private Vector3 _patrolTarget { get; set; }
|
||||
public Transition On(in Input.Alerted _)
|
||||
{
|
||||
return To<FollowPlayer>();
|
||||
@@ -19,22 +20,13 @@ public partial class EnemyLogic
|
||||
{
|
||||
var delta = input.Delta;
|
||||
var enemy = Get<IEnemy>();
|
||||
var targetPosition = enemy.NavAgent.GetNextPathPosition();
|
||||
var velocity = (targetPosition - enemy.GlobalPosition).Normalized() * 1.0f * (float)delta;
|
||||
var lookAtDir = enemy.GlobalTransform.Origin - velocity;
|
||||
|
||||
var lookAtPosition = new Vector3(lookAtDir.X, enemy.GlobalPosition.Y, lookAtDir.Z);
|
||||
if (enemy.GlobalPosition.DistanceTo(targetPosition) > 1.0f && !velocity.IsEqualApprox(Vector3.Zero) && !enemy.GlobalPosition.IsEqualApprox(lookAtPosition))
|
||||
enemy.LookAt(lookAtPosition);
|
||||
|
||||
Output(new Output.MovementComputed(velocity));
|
||||
enemy.MoveToLocation(_patrolTarget, (float)delta);
|
||||
return ToSelf();
|
||||
}
|
||||
|
||||
public Transition On(in Input.PatrolToRandomSpot input)
|
||||
{
|
||||
var enemy = Get<IEnemy>();
|
||||
enemy.NavAgent.TargetPosition = input.PatrolTarget;
|
||||
_patrolTarget = input.PatrolTarget;
|
||||
return ToSelf();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user