added animation playing in behavior trees

This commit is contained in:
Lilith Schier 2026-06-27 17:58:25 +02:00
parent d362d93b12
commit c9967f09d9
2 changed files with 50 additions and 11 deletions

View file

@ -26,7 +26,7 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
private float _hp;
private Behavior.Tree Tree { get; set; } = null!;
private Bt.Tree Tree { get; set; } = null!;
private float TargetVelocity { get; set; }
private MotionGoal _motionGoal = new MotionGoal.Stop();
@ -59,19 +59,17 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
new Bt.Check(() => StabHitbox.GetOverlappingBodies().Contains(Target)),
new Bt.MemoSequence([
new Bt.Action(Stop),
new Bt.Action(() => AnimationPlayer.Play("prepare_attack")),
new Bt.PlayAnimation("prepare_attack"),
new Bt.Delay(0.4) { RandomVariation = 0.2 },
]),
]),
new Bt.Action(() =>
{
AnimationPlayer.Play("stab");
_state = State.Attacking;
}),
new Bt.WaitUntil(() => _state is State.Idle),
new Bt.PlayAnimation("stab"),
new Bt.Action(() => _state = State.Attacking),
new Bt.WaitUntil(() => _state is not State.Attacking),
]),
new Bt.MemoSequence([
new Bt.Delay(0.1) { RandomVariation = 0.05 },
new Bt.PlayAnimation("idle"),
new Bt.Action(() =>
{
var left = Target!.GlobalPosition + Vector2.Left * AttackDistance;
@ -81,7 +79,6 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
< GlobalPosition.DistanceSquaredTo(right)
? left
: right;
AnimationPlayer.Play("idle");
return WalkTo(targetPosition)
? Bt.Result.Success
: Bt.Result.Running;
@ -91,11 +88,14 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
]),
new Bt.MemoSequence([
new Bt.Check(() => _state is State.Idle),
new Bt.Action(() => AnimationPlayer.Play("idle")),
new Bt.PlayAnimation("idle"),
new Bt.DoNothing(),
]),
])
);
)
{
AnimationPlayer = AnimationPlayer,
};
public void OnReady()
{