use Player.DesiredTarget

controller-support
HumanoidSandvichDispenser 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) .WithPitchDeviation(0.125f)
.Play(); .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"); "up", "down");
Character.LookTowardsDirection(); Character.LookTowardsDirection();
Vector2 mousePos = Character.GetGlobalMousePosition(); var player = _player;
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos); player.DesiredTarget = player.GetDesiredInputFromInput();
Vector2 joystick = Godot.Input.GetVector("look_left", "look_right",
"look_up", "look_down");
if (Character.Inventory.SelectedItem is Items.Weapon weapon) if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{ {
@ -67,24 +65,7 @@ public abstract partial class PlayerState : CharacterState
if (!weapon.ShouldHideIdle || isAttack1On) if (!weapon.ShouldHideIdle || isAttack1On)
{ {
var inputMethod = Utils.World.Instance.GlobalState player.Target = player.DesiredTarget;
.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;
}
} }
if (isAttack1On) if (isAttack1On)
@ -95,7 +76,6 @@ public abstract partial class PlayerState : CharacterState
{ {
Character.UseCurrentItemAlt(); Character.UseCurrentItemAlt();
} }
} }
return base.Process(delta); return base.Process(delta);