Улучшен поиск путей
This commit is contained in:
parent
3e60215e11
commit
26cc09241f
8 changed files with 107 additions and 18 deletions
|
@ -50,11 +50,14 @@ public partial class Wretched : CharacterBody2D
|
|||
private State _state;
|
||||
private float _timeSinceState;
|
||||
private AnimatedSprite2D _sprite;
|
||||
private NavigationAgent2D _nav;
|
||||
private bool _isActivated;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_nav = (NavigationAgent2D)FindChild("NavigationAgent2D");
|
||||
_nav.VelocityComputed += OnNavVelocityCompute;
|
||||
CurrentState = State.Waiting;
|
||||
var animationName = "NonActivatedSide";
|
||||
switch (Facing)
|
||||
|
@ -93,8 +96,8 @@ public partial class Wretched : CharacterBody2D
|
|||
break;
|
||||
|
||||
case State.Moving:
|
||||
var direction = (Player.Instance.Position - Position).Normalized();
|
||||
Velocity = direction * MovingSpeed;
|
||||
_nav.TargetPosition = Player.Instance.Position;
|
||||
var direction = (_nav.GetNextPathPosition() - Position).Normalized();
|
||||
|
||||
var animationName = "ActivatedSide";
|
||||
|
||||
|
@ -108,6 +111,7 @@ public partial class Wretched : CharacterBody2D
|
|||
|
||||
_sprite.FlipH = Velocity.X < 0.001f && animationName == "ActivatedSide";
|
||||
_sprite.Play(animationName);
|
||||
_nav.Velocity = direction * MovingSpeed;
|
||||
MoveAndSlide();
|
||||
break;
|
||||
}
|
||||
|
@ -158,4 +162,9 @@ public partial class Wretched : CharacterBody2D
|
|||
EmitSignal(SignalName.Killed);
|
||||
QueueFree(); // TODO
|
||||
}
|
||||
|
||||
private void OnNavVelocityCompute(Vector2 safeVelocity)
|
||||
{
|
||||
Velocity = safeVelocity;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue