39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using Chickensoft.Introspection;
|
|
using Godot;
|
|
|
|
namespace GameJamDungeon;
|
|
|
|
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>, IGet<Input.PatrolToRandomSpot>
|
|
{
|
|
public Transition On(in Input.Alerted _)
|
|
{
|
|
return To<FollowPlayer>();
|
|
}
|
|
|
|
public Transition On(in Input.PhysicsTick input)
|
|
{
|
|
var delta = input.Delta;
|
|
var enemy = Get<IEnemy>();
|
|
var targetPosition = enemy.NavAgent.GetNextPathPosition();
|
|
var velocity = (targetPosition - enemy.GlobalPosition).Normalized() * 3.0f;
|
|
enemy.Velocity = velocity;
|
|
enemy.Rotation = new Vector3(0, (float)Mathf.LerpAngle(enemy.Rotation.Y, Mathf.Atan2(enemy.Velocity.X, enemy.Velocity.Z), delta * 10.0), 0);
|
|
|
|
Output(new Output.MovementComputed());
|
|
return ToSelf();
|
|
}
|
|
|
|
public Transition On(in Input.PatrolToRandomSpot input)
|
|
{
|
|
var enemy = Get<IEnemy>();
|
|
enemy.NavAgent.TargetPosition = input.PatrolTarget;
|
|
return ToSelf();
|
|
}
|
|
}
|
|
}
|
|
} |