Player looks in last direction; fix #17

pull/6/head
John Montagu, the 4th Earl of Sandvich 2023-09-06 23:18:53 -07:00
parent 17104e7b74
commit 88c296dd13
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
3 changed files with 29 additions and 4 deletions

View File

@ -130,7 +130,14 @@ public partial class Character : CharacterBody2D, IFaction
StunAnimation.Stop();
}
Sprite.FlipH = Target.X < 0;
if (Target.X < 0)
{
Sprite.FlipH = true;
}
else if (Target.X > 0)
{
Sprite.FlipH = false;
}
DrawTarget();
}
@ -214,7 +221,7 @@ public partial class Character : CharacterBody2D, IFaction
scale.Y = -1;
angle = Mathf.Pi - angle;
}
else
else if (target.X > 0)
{
scale.Y = 1;
}

View File

@ -11,7 +11,20 @@ public sealed partial class Player : Character
{
private string _spriteAnim;
public Vector2 DesiredTarget { get; set; }
private Vector2 _desiredTarget;
public Vector2 DesiredTarget
{
get => _desiredTarget;
set
{
if (value.IsZeroApprox())
{
return;
}
_desiredTarget = value;
}
}
[Export]
public PlayerCamera Camera { get; set; }

View File

@ -56,7 +56,12 @@ public abstract partial class PlayerState : CharacterState
Character.LookTowardsDirection();
var player = _player;
player.DesiredTarget = player.GetDesiredInputFromInput();
var desiredTarget = player.GetDesiredInputFromInput();
if (!desiredTarget.IsZeroApprox())
{
// can never be zero
player.DesiredTarget = desiredTarget;
}
if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{