use Player.DesiredTarget

pull/6/head
John Montagu, the 4th Earl of Sandvich 2023-09-06 23:07:51 -07:00
parent 6c5bc4edac
commit 17104e7b74
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
2 changed files with 25 additions and 23 deletions

View File

@ -119,4 +119,26 @@ public sealed partial class Player : Character
.WithPitchDeviation(0.125f)
.Play();
}
public Vector2 GetDesiredInputFromInput()
{
Vector2 mousePos = GetGlobalMousePosition();
Vector2 dirToMouse = GlobalPosition.DirectionTo(mousePos);
Vector2 joystick = Godot.Input.GetVector("look_left", "look_right",
"look_up", "look_down");
var inputMethod = Utils.World.Instance.GlobalState
.Settings.InputMethod;
switch (inputMethod)
{
case State.Global.InputMethod.Joystick:
if (joystick.IsZeroApprox())
{
return Direction;
}
return joystick;
default:
return dirToMouse;
}
}
}

View File

@ -55,10 +55,8 @@ public abstract partial class PlayerState : CharacterState
"up", "down");
Character.LookTowardsDirection();
Vector2 mousePos = Character.GetGlobalMousePosition();
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos);
Vector2 joystick = Godot.Input.GetVector("look_left", "look_right",
"look_up", "look_down");
var player = _player;
player.DesiredTarget = player.GetDesiredInputFromInput();
if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{
@ -67,24 +65,7 @@ public abstract partial class PlayerState : CharacterState
if (!weapon.ShouldHideIdle || isAttack1On)
{
var inputMethod = Utils.World.Instance.GlobalState
.Settings.InputMethod;
switch (inputMethod)
{
case Global.InputMethod.Joystick:
if (joystick.IsZeroApprox())
{
Character.Target = Character.Direction;
}
else
{
Character.Target = joystick;
}
break;
default:
Character.Target = dirToMouse;
break;
}
player.Target = player.DesiredTarget;
}
if (isAttack1On)
@ -95,7 +76,6 @@ public abstract partial class PlayerState : CharacterState
{
Character.UseCurrentItemAlt();
}
}
return base.Process(delta);