From ffc73f0766ef1f2d2cc07376238d0311887211b5 Mon Sep 17 00:00:00 2001 From: pro2p Date: Wed, 6 May 2026 22:46:20 +0200 Subject: [PATCH 1/6] two players can play on one keyboard A few other bugs were fixed --- .../Game/Features/Input/EmptyInputProvider.cs | 1 + Assets/Game/Features/Input/IInputProvider.cs | 1 + .../Features/Input/PlayerInputProvider.cs | 29 ++- Assets/Game/Features/Lobby/TankSpawnerView.cs | 45 ++-- Assets/Game/Features/Shield/ShieldAbility.cs | 2 +- Assets/Game/Features/Tank/Tank.cs | 12 +- Assets/Game/Features/World/WorldConstants.cs | 1 + Assets/Game/InputActions.cs | 213 ++++++++++++++---- Assets/Game/InputActions.inputactions | 188 ++++++++++++---- 9 files changed, 381 insertions(+), 111 deletions(-) diff --git a/Assets/Game/Features/Input/EmptyInputProvider.cs b/Assets/Game/Features/Input/EmptyInputProvider.cs index 445db53..f0929c4 100644 --- a/Assets/Game/Features/Input/EmptyInputProvider.cs +++ b/Assets/Game/Features/Input/EmptyInputProvider.cs @@ -2,6 +2,7 @@ { public class EmptyInputProvider : IInputProvider { + public bool IsTruePlayer() => false; public Vector2Int GetMilliAimingDir() => Vector2Int.Zero; public bool ShouldDash() => false; diff --git a/Assets/Game/Features/Input/IInputProvider.cs b/Assets/Game/Features/Input/IInputProvider.cs index cabeb48..3414103 100644 --- a/Assets/Game/Features/Input/IInputProvider.cs +++ b/Assets/Game/Features/Input/IInputProvider.cs @@ -2,6 +2,7 @@ { public interface IInputProvider { + public bool IsTruePlayer(); public Vector2Int GetMilliMovementDir(); public Vector2Int GetMilliAimingDir(); public bool ShouldShoot(); diff --git a/Assets/Game/Features/Input/PlayerInputProvider.cs b/Assets/Game/Features/Input/PlayerInputProvider.cs index ba5b7b0..88d0f7f 100644 --- a/Assets/Game/Features/Input/PlayerInputProvider.cs +++ b/Assets/Game/Features/Input/PlayerInputProvider.cs @@ -1,3 +1,4 @@ +using Automathon.Game.World; using UnityEngine; using UnityEngine.InputSystem; @@ -5,7 +6,8 @@ namespace Automathon.Game.Input { public class PlayerInputProvider : IInputProvider { - private bool isGamepad; + public enum playerControlsType { Left, Right, Gamepad } + public playerControlsType PlayerControls { get; private set; } private InputAction dashAction; private InputAction grenadeAction; private InputAction shieldAction; @@ -14,7 +16,18 @@ public class PlayerInputProvider : IInputProvider private InputAction aimAction; public PlayerInputProvider(PlayerInput playerInput) { - isGamepad = playerInput.currentControlScheme == "Gamepad"; + if (playerInput.currentControlScheme == "Gamepad") + { + PlayerControls = playerControlsType.Gamepad; + } + else if (playerInput.currentControlScheme == "Keyboard_left") + { + PlayerControls = playerControlsType.Left; + } + else if (playerInput.currentControlScheme == "Keyboard_right") + { + PlayerControls = playerControlsType.Right; + } dashAction = playerInput.actions["Dash"]; grenadeAction = playerInput.actions["Grenade"]; shieldAction = playerInput.actions["Shield"]; @@ -23,6 +36,8 @@ public PlayerInputProvider(PlayerInput playerInput) aimAction = playerInput.actions["Aim"]; } + public bool IsTruePlayer() => true; + public bool ShouldDash() => dashAction.IsPressed(); public bool ShouldGrenade() => grenadeAction.IsPressed(); @@ -39,13 +54,13 @@ public Vector2Int GetMilliMovementDir() public Vector2Int GetMilliAimingDir() { - if (isGamepad) + Vector2 aimingDir = aimAction.ReadValue(); + if (PlayerControls == playerControlsType.Right) { - Vector2 aimingDir = aimAction.ReadValue(); - return new Vector2Int((int)(aimingDir.x * 1000), (int)(aimingDir.y * 1000)); + Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(aimingDir.x, aimingDir.y, WorldConstants.CAMERA_DISTANCE / 1000)); + return new Vector2Int((int)(worldPos.x * WorldConstants.SPACE_SCALE), (int)(worldPos.y * WorldConstants.SPACE_SCALE)); } - - return GetMilliMovementDir(); + return new Vector2Int((int)(aimingDir.x * 1000), (int)(aimingDir.y * 1000)); } } } \ No newline at end of file diff --git a/Assets/Game/Features/Lobby/TankSpawnerView.cs b/Assets/Game/Features/Lobby/TankSpawnerView.cs index c6e81ca..1d1d96f 100644 --- a/Assets/Game/Features/Lobby/TankSpawnerView.cs +++ b/Assets/Game/Features/Lobby/TankSpawnerView.cs @@ -13,31 +13,38 @@ public class TankSpawnerView : MonoBehaviour [SerializeField] private PlayerInputManager playerInputManager; private Dictionary inputProviders = new(); + private void Awake() + { + playerInputManager.onPlayerLeft += OnPlayerLeft; + } + private void Update() { if (GameplayManager.State != GameplayManager.GameState.Lobby) return; - playerInputManager.onPlayerLeft += OnPlayerLeft; - HandleGamepadJoinInput(); HandleKeyboardJoinInput(); - if (Keyboard.current != null && Keyboard.current.escapeKey.wasPressedThisFrame) + if (Keyboard.current != null) { - PlayerInput playerInputToRemove = null; - - foreach (PlayerInput playerInput in inputProviders.Keys) + if (Keyboard.current.escapeKey.wasPressedThisFrame || Keyboard.current.deleteKey.wasPressedThisFrame) { - if (playerInput.currentControlScheme == "Keyboard&Mouse") + bool left = Keyboard.current.escapeKey.wasPressedThisFrame; + PlayerInput playerInputToRemove = null; + + foreach (PlayerInput playerInput in inputProviders.Keys) { - playerInputToRemove = playerInput; - break; + if ((left && playerInput.currentControlScheme == "Keyboard_left") || (!left && playerInput.currentControlScheme == "Keyboard_right")) + { + playerInputToRemove = playerInput; + break; + } } - } - if (playerInputToRemove != null) - OnPlayerLeft(playerInputToRemove); + if (playerInputToRemove != null) + OnPlayerLeft(playerInputToRemove); + } } } @@ -49,7 +56,12 @@ private void HandleKeyboardJoinInput() if (keyboard.eKey.wasPressedThisFrame || keyboard.wKey.wasPressedThisFrame || keyboard.aKey.wasPressedThisFrame || keyboard.sKey.wasPressedThisFrame || keyboard.dKey.wasPressedThisFrame || keyboard.qKey.wasPressedThisFrame) { - JoinKeyboardPlayer(); + JoinKeyboardPlayer(true); + } + else if (keyboard.upArrowKey.wasPressedThisFrame || keyboard.downArrowKey.wasPressedThisFrame || keyboard.leftArrowKey.wasPressedThisFrame || + keyboard.rightArrowKey.wasPressedThisFrame || keyboard.rightShiftKey.wasPressedThisFrame || keyboard.slashKey.wasPressedThisFrame) + { + JoinKeyboardPlayer(false); } } @@ -103,23 +115,24 @@ private void JoinGamepadPlayer(Gamepad gamepad) SpawnTank(playerInput); } - private void JoinKeyboardPlayer() + private void JoinKeyboardPlayer(bool isLeft) { if (PlayerInput.all.Count >= playerInputManager.maxPlayerCount) return; foreach (PlayerInput playerInputTemp in inputProviders.Keys) { - if (playerInputTemp.currentControlScheme == "Keyboard&Mouse") + if ((isLeft && playerInputTemp.currentControlScheme == "Keyboard_left") || (!isLeft && playerInputTemp.currentControlScheme == "Keyboard_right")) return; } // 2. Manually trigger the join // We pass -1 for playerIndex to let Unity assign the next available index (0, 1, 2, etc.) + string controlScheme = isLeft ? "Keyboard_left" : "Keyboard_right"; PlayerInput playerInput = playerInputManager.JoinPlayer( playerIndex: -1, splitScreenIndex: -1, - controlScheme: "Keyboard&Mouse", + controlScheme: controlScheme, pairWithDevice: Keyboard.current ); diff --git a/Assets/Game/Features/Shield/ShieldAbility.cs b/Assets/Game/Features/Shield/ShieldAbility.cs index 20398f2..3bab86d 100644 --- a/Assets/Game/Features/Shield/ShieldAbility.cs +++ b/Assets/Game/Features/Shield/ShieldAbility.cs @@ -17,7 +17,7 @@ public ShieldAbility(Func shouldActivate) : base(cooldown: COOLDOWN_MILLIS protected override void Activate() { Vector2Int position = Tank.Position + Tank.LastMilliDirection * SPAWN_DISTANCE_FROM_TANK / 1000; - int rotationMilliRad = Tank.RotationMilli + IntMath.PI_MILLI / 2; + int rotationMilliRad = Tank.LastMilliDirection.CalculateAngleMilliRad() + IntMath.PI_MILLI / 2; GameplayManager.Instantiate(new Shield(position, rotationMilliRad)); } diff --git a/Assets/Game/Features/Tank/Tank.cs b/Assets/Game/Features/Tank/Tank.cs index bd3f506..fd28e21 100644 --- a/Assets/Game/Features/Tank/Tank.cs +++ b/Assets/Game/Features/Tank/Tank.cs @@ -44,16 +44,22 @@ public override void Update() rigidbody.Velocity = movementInput * SPEED / 1000; Vector2Int directionInput = InputProvider.GetMilliAimingDir(); + if (InputProvider.IsTruePlayer() && ((PlayerInputProvider)InputProvider).PlayerControls == PlayerInputProvider.playerControlsType.Right) + { + directionInput = new Vector2Int(directionInput.X - Position.X, directionInput.Y - Position.Y); + } directionInput.NormalizeAtScale(1000); if (directionInput != Vector2Int.Zero) { - RotationMilli = directionInput.CalculateAngleMilliRad(); - rigidbody.AngularVelocityMilli = 0; - LastMilliDirection = directionInput; LastMilliDirection.NormalizeAtScale(1000); } + if (movementInput != Vector2Int.Zero) + { + RotationMilli = movementInput.CalculateAngleMilliRad(); + rigidbody.AngularVelocityMilli = 0; + } } private void Death() diff --git a/Assets/Game/Features/World/WorldConstants.cs b/Assets/Game/Features/World/WorldConstants.cs index eadd1ac..5e3d06f 100644 --- a/Assets/Game/Features/World/WorldConstants.cs +++ b/Assets/Game/Features/World/WorldConstants.cs @@ -3,5 +3,6 @@ public static class WorldConstants { public const int SPACE_SCALE = 1000; + public const int CAMERA_DISTANCE = 10000; } } diff --git a/Assets/Game/InputActions.cs b/Assets/Game/InputActions.cs index 810ca5a..412237f 100644 --- a/Assets/Game/InputActions.cs +++ b/Assets/Game/InputActions.cs @@ -2,7 +2,7 @@ // // This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator // version 1.17.0 -// from Assets/InputActions.inputactions +// from Assets/Game/InputActions.inputactions // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -16,7 +16,7 @@ using UnityEngine.InputSystem.Utilities; /// -/// Provides programmatic access to , , and instances defined in asset "Assets/InputActions.inputactions". +/// Provides programmatic access to , , and instances defined in asset "Assets/Game/InputActions.inputactions". /// /// /// This class is source generated and any manual edits will be discarded if the associated asset is reimported or modified. @@ -176,7 +176,7 @@ public @InputActions() ""path"": ""/w"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": "";Keyboard_left"", ""action"": ""Move"", ""isComposite"": false, ""isPartOfComposite"": true @@ -187,7 +187,7 @@ public @InputActions() ""path"": ""/upArrow"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Move"", ""isComposite"": false, ""isPartOfComposite"": true @@ -198,7 +198,7 @@ public @InputActions() ""path"": ""/s"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_left"", ""action"": ""Move"", ""isComposite"": false, ""isPartOfComposite"": true @@ -209,7 +209,7 @@ public @InputActions() ""path"": ""/downArrow"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Move"", ""isComposite"": false, ""isPartOfComposite"": true @@ -220,7 +220,7 @@ public @InputActions() ""path"": ""/a"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_left"", ""action"": ""Move"", ""isComposite"": false, ""isPartOfComposite"": true @@ -231,7 +231,7 @@ public @InputActions() ""path"": ""/leftArrow"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Move"", ""isComposite"": false, ""isPartOfComposite"": true @@ -242,7 +242,7 @@ public @InputActions() ""path"": ""/d"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_left"", ""action"": ""Move"", ""isComposite"": false, ""isPartOfComposite"": true @@ -253,7 +253,7 @@ public @InputActions() ""path"": ""/rightArrow"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Move"", ""isComposite"": false, ""isPartOfComposite"": true @@ -293,22 +293,77 @@ public @InputActions() }, { ""name"": """", - ""id"": ""8c8e490b-c610-4785-884f-f04217b23ca4"", - ""path"": ""/delta"", + ""id"": ""3e5f5442-8668-4b27-a940-df99bad7e831"", + ""path"": ""/{Hatswitch}"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse;Touch"", + ""groups"": ""Joystick"", ""action"": ""Aim"", ""isComposite"": false, ""isPartOfComposite"": false }, + { + ""name"": ""2D Vector"", + ""id"": ""6462fc8f-9047-4240-a471-508c3252359a"", + ""path"": ""2DVector"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Aim"", + ""isComposite"": true, + ""isPartOfComposite"": false + }, + { + ""name"": ""up"", + ""id"": ""1195dda2-a658-4f83-b574-5938f0cba4c7"", + ""path"": ""/t"", + ""interactions"": """", + ""processors"": """", + ""groups"": "";Keyboard_left"", + ""action"": ""Aim"", + ""isComposite"": false, + ""isPartOfComposite"": true + }, + { + ""name"": ""down"", + ""id"": ""253a1b00-b404-400d-a9e1-fd0374c6433b"", + ""path"": ""/g"", + ""interactions"": """", + ""processors"": """", + ""groups"": "";Keyboard_left"", + ""action"": ""Aim"", + ""isComposite"": false, + ""isPartOfComposite"": true + }, + { + ""name"": ""left"", + ""id"": ""4e1e488c-2107-4847-afcb-9e3c270056f4"", + ""path"": ""/f"", + ""interactions"": """", + ""processors"": """", + ""groups"": "";Keyboard_left"", + ""action"": ""Aim"", + ""isComposite"": false, + ""isPartOfComposite"": true + }, + { + ""name"": ""right"", + ""id"": ""61433514-0ac9-46d8-a395-37d757bc763e"", + ""path"": ""/h"", + ""interactions"": """", + ""processors"": """", + ""groups"": "";Keyboard_left"", + ""action"": ""Aim"", + ""isComposite"": false, + ""isPartOfComposite"": true + }, { ""name"": """", - ""id"": ""3e5f5442-8668-4b27-a940-df99bad7e831"", - ""path"": ""/{Hatswitch}"", + ""id"": ""240dd67c-96e6-4ce3-998e-2b70964276e3"", + ""path"": ""/position"", ""interactions"": """", ""processors"": """", - ""groups"": ""Joystick"", + ""groups"": "";Keyboard_right"", ""action"": ""Aim"", ""isComposite"": false, ""isPartOfComposite"": false @@ -330,7 +385,7 @@ public @InputActions() ""path"": ""/leftButton"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Shoot"", ""isComposite"": false, ""isPartOfComposite"": false @@ -371,10 +426,10 @@ public @InputActions() { ""name"": """", ""id"": ""b3c1c7f0-bd20-4ee7-a0f1-899b24bca6d7"", - ""path"": ""/enter"", + ""path"": ""/space"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_left"", ""action"": ""Shoot"", ""isComposite"": false, ""isPartOfComposite"": false @@ -385,7 +440,7 @@ public @InputActions() ""path"": ""/leftShoulder"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Gamepad"", ""action"": ""Dash"", ""isComposite"": false, ""isPartOfComposite"": false @@ -412,13 +467,35 @@ public @InputActions() ""isComposite"": false, ""isPartOfComposite"": false }, + { + ""name"": """", + ""id"": ""b967a280-4a3e-4f28-82a7-b4298ddd5ed7"", + ""path"": ""/leftShift"", + ""interactions"": """", + ""processors"": """", + ""groups"": "";Keyboard_left"", + ""action"": ""Dash"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""1eee1e79-9688-4dfc-a740-94fe72d31c1e"", + ""path"": ""/slash"", + ""interactions"": """", + ""processors"": """", + ""groups"": "";Keyboard_right"", + ""action"": ""Dash"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, { ""name"": """", ""id"": ""1c04ea5f-b012-41d1-a6f7-02e963b52893"", ""path"": ""/e"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_left"", ""action"": ""Shield"", ""isComposite"": false, ""isPartOfComposite"": false @@ -434,6 +511,17 @@ public @InputActions() ""isComposite"": false, ""isPartOfComposite"": false }, + { + ""name"": """", + ""id"": ""b1b3aa23-4a1b-4825-ae5e-15907f8a3e9c"", + ""path"": ""/rightShift"", + ""interactions"": """", + ""processors"": """", + ""groups"": "";Keyboard_right"", + ""action"": ""Shield"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, { ""name"": """", ""id"": ""4f4649ac-64a8-4a73-af11-b3faef356a4d"", @@ -451,7 +539,18 @@ public @InputActions() ""path"": ""/rightButton"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", + ""action"": ""Grenade"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""6d5d90a0-dded-4b6e-82fe-ba1431e2ada5"", + ""path"": ""/q"", + ""interactions"": """", + ""processors"": """", + ""groups"": "";Keyboard_left"", ""action"": ""Grenade"", ""isComposite"": false, ""isPartOfComposite"": false @@ -736,7 +835,7 @@ public @InputActions() ""path"": ""/w"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Navigate"", ""isComposite"": false, ""isPartOfComposite"": true @@ -747,7 +846,7 @@ public @InputActions() ""path"": ""/upArrow"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Navigate"", ""isComposite"": false, ""isPartOfComposite"": true @@ -758,7 +857,7 @@ public @InputActions() ""path"": ""/s"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Navigate"", ""isComposite"": false, ""isPartOfComposite"": true @@ -769,7 +868,7 @@ public @InputActions() ""path"": ""/downArrow"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Navigate"", ""isComposite"": false, ""isPartOfComposite"": true @@ -780,7 +879,7 @@ public @InputActions() ""path"": ""/a"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Navigate"", ""isComposite"": false, ""isPartOfComposite"": true @@ -791,7 +890,7 @@ public @InputActions() ""path"": ""/leftArrow"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Navigate"", ""isComposite"": false, ""isPartOfComposite"": true @@ -802,7 +901,7 @@ public @InputActions() ""path"": ""/d"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Navigate"", ""isComposite"": false, ""isPartOfComposite"": true @@ -813,7 +912,7 @@ public @InputActions() ""path"": ""/rightArrow"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Navigate"", ""isComposite"": false, ""isPartOfComposite"": true @@ -824,7 +923,7 @@ public @InputActions() ""path"": ""*/{Submit}"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse;Gamepad;Touch;Joystick;XR"", + ""groups"": ""Gamepad;Touch;Joystick;XR;Keyboard_right"", ""action"": ""Submit"", ""isComposite"": false, ""isPartOfComposite"": false @@ -835,7 +934,7 @@ public @InputActions() ""path"": ""*/{Cancel}"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse;Gamepad;Touch;Joystick;XR"", + ""groups"": ""Gamepad;Touch;Joystick;XR;Keyboard_right"", ""action"": ""Cancel"", ""isComposite"": false, ""isPartOfComposite"": false @@ -846,7 +945,7 @@ public @InputActions() ""path"": ""/position"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Point"", ""isComposite"": false, ""isPartOfComposite"": false @@ -857,7 +956,7 @@ public @InputActions() ""path"": ""/position"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Point"", ""isComposite"": false, ""isPartOfComposite"": false @@ -879,7 +978,7 @@ public @InputActions() ""path"": ""/leftButton"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Click"", ""isComposite"": false, ""isPartOfComposite"": false @@ -890,7 +989,7 @@ public @InputActions() ""path"": ""/tip"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""Click"", ""isComposite"": false, ""isPartOfComposite"": false @@ -923,7 +1022,7 @@ public @InputActions() ""path"": ""/scroll"", ""interactions"": """", ""processors"": """", - ""groups"": "";Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""ScrollWheel"", ""isComposite"": false, ""isPartOfComposite"": false @@ -934,7 +1033,7 @@ public @InputActions() ""path"": ""/rightButton"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""RightClick"", ""isComposite"": false, ""isPartOfComposite"": false @@ -945,7 +1044,7 @@ public @InputActions() ""path"": ""/middleButton"", ""interactions"": """", ""processors"": """", - ""groups"": ""Keyboard&Mouse"", + ""groups"": ""Keyboard_right"", ""action"": ""MiddleClick"", ""isComposite"": false, ""isPartOfComposite"": false @@ -977,8 +1076,8 @@ public @InputActions() ], ""controlSchemes"": [ { - ""name"": ""Keyboard&Mouse"", - ""bindingGroup"": ""Keyboard&Mouse"", + ""name"": ""Keyboard_right"", + ""bindingGroup"": ""Keyboard_right"", ""devices"": [ { ""devicePath"": """", @@ -1046,6 +1145,17 @@ public @InputActions() ""isOR"": false } ] + }, + { + ""name"": ""Keyboard_left"", + ""bindingGroup"": ""Keyboard_left"", + ""devices"": [ + { + ""devicePath"": """", + ""isOptional"": false, + ""isOR"": false + } + ] } ] }"); @@ -1492,17 +1602,17 @@ public void SetCallbacks(IUIActions instance) /// Provides a new instance referencing this action map. /// public UIActions @UI => new UIActions(this); - private int m_KeyboardMouseSchemeIndex = -1; + private int m_Keyboard_rightSchemeIndex = -1; /// /// Provides access to the input control scheme. /// /// - public InputControlScheme KeyboardMouseScheme + public InputControlScheme Keyboard_rightScheme { get { - if (m_KeyboardMouseSchemeIndex == -1) m_KeyboardMouseSchemeIndex = asset.FindControlSchemeIndex("Keyboard&Mouse"); - return asset.controlSchemes[m_KeyboardMouseSchemeIndex]; + if (m_Keyboard_rightSchemeIndex == -1) m_Keyboard_rightSchemeIndex = asset.FindControlSchemeIndex("Keyboard_right"); + return asset.controlSchemes[m_Keyboard_rightSchemeIndex]; } } private int m_GamepadSchemeIndex = -1; @@ -1570,6 +1680,19 @@ public InputControlScheme WASDScheme return asset.controlSchemes[m_WASDSchemeIndex]; } } + private int m_Keyboard_leftSchemeIndex = -1; + /// + /// Provides access to the input control scheme. + /// + /// + public InputControlScheme Keyboard_leftScheme + { + get + { + if (m_Keyboard_leftSchemeIndex == -1) m_Keyboard_leftSchemeIndex = asset.FindControlSchemeIndex("Keyboard_left"); + return asset.controlSchemes[m_Keyboard_leftSchemeIndex]; + } + } /// /// Interface to implement callback methods for all input action callbacks associated with input actions defined by "Player" which allows adding and removing callbacks. /// diff --git a/Assets/Game/InputActions.inputactions b/Assets/Game/InputActions.inputactions index 9d39c9d..4261bdc 100644 --- a/Assets/Game/InputActions.inputactions +++ b/Assets/Game/InputActions.inputactions @@ -90,7 +90,7 @@ "path": "/w", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": ";Keyboard_left", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -101,7 +101,7 @@ "path": "/upArrow", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -112,7 +112,7 @@ "path": "/s", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_left", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -123,7 +123,7 @@ "path": "/downArrow", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -134,7 +134,7 @@ "path": "/a", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_left", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -145,7 +145,7 @@ "path": "/leftArrow", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -156,7 +156,7 @@ "path": "/d", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_left", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -167,7 +167,7 @@ "path": "/rightArrow", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Move", "isComposite": false, "isPartOfComposite": true @@ -207,22 +207,77 @@ }, { "name": "", - "id": "8c8e490b-c610-4785-884f-f04217b23ca4", - "path": "/delta", + "id": "3e5f5442-8668-4b27-a940-df99bad7e831", + "path": "/{Hatswitch}", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse;Touch", + "groups": "Joystick", "action": "Aim", "isComposite": false, "isPartOfComposite": false }, + { + "name": "2D Vector", + "id": "6462fc8f-9047-4240-a471-508c3252359a", + "path": "2DVector", + "interactions": "", + "processors": "", + "groups": "", + "action": "Aim", + "isComposite": true, + "isPartOfComposite": false + }, + { + "name": "up", + "id": "1195dda2-a658-4f83-b574-5938f0cba4c7", + "path": "/t", + "interactions": "", + "processors": "", + "groups": ";Keyboard_left", + "action": "Aim", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "down", + "id": "253a1b00-b404-400d-a9e1-fd0374c6433b", + "path": "/g", + "interactions": "", + "processors": "", + "groups": ";Keyboard_left", + "action": "Aim", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "left", + "id": "4e1e488c-2107-4847-afcb-9e3c270056f4", + "path": "/f", + "interactions": "", + "processors": "", + "groups": ";Keyboard_left", + "action": "Aim", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "right", + "id": "61433514-0ac9-46d8-a395-37d757bc763e", + "path": "/h", + "interactions": "", + "processors": "", + "groups": ";Keyboard_left", + "action": "Aim", + "isComposite": false, + "isPartOfComposite": true + }, { "name": "", - "id": "3e5f5442-8668-4b27-a940-df99bad7e831", - "path": "/{Hatswitch}", + "id": "240dd67c-96e6-4ce3-998e-2b70964276e3", + "path": "/position", "interactions": "", "processors": "", - "groups": "Joystick", + "groups": ";Keyboard_right", "action": "Aim", "isComposite": false, "isPartOfComposite": false @@ -244,7 +299,7 @@ "path": "/leftButton", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Shoot", "isComposite": false, "isPartOfComposite": false @@ -285,10 +340,10 @@ { "name": "", "id": "b3c1c7f0-bd20-4ee7-a0f1-899b24bca6d7", - "path": "/enter", + "path": "/space", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_left", "action": "Shoot", "isComposite": false, "isPartOfComposite": false @@ -299,7 +354,7 @@ "path": "/leftShoulder", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Gamepad", "action": "Dash", "isComposite": false, "isPartOfComposite": false @@ -326,13 +381,35 @@ "isComposite": false, "isPartOfComposite": false }, + { + "name": "", + "id": "b967a280-4a3e-4f28-82a7-b4298ddd5ed7", + "path": "/leftShift", + "interactions": "", + "processors": "", + "groups": ";Keyboard_left", + "action": "Dash", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "1eee1e79-9688-4dfc-a740-94fe72d31c1e", + "path": "/slash", + "interactions": "", + "processors": "", + "groups": ";Keyboard_right", + "action": "Dash", + "isComposite": false, + "isPartOfComposite": false + }, { "name": "", "id": "1c04ea5f-b012-41d1-a6f7-02e963b52893", "path": "/e", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_left", "action": "Shield", "isComposite": false, "isPartOfComposite": false @@ -348,6 +425,17 @@ "isComposite": false, "isPartOfComposite": false }, + { + "name": "", + "id": "b1b3aa23-4a1b-4825-ae5e-15907f8a3e9c", + "path": "/rightShift", + "interactions": "", + "processors": "", + "groups": ";Keyboard_right", + "action": "Shield", + "isComposite": false, + "isPartOfComposite": false + }, { "name": "", "id": "4f4649ac-64a8-4a73-af11-b3faef356a4d", @@ -365,7 +453,18 @@ "path": "/rightButton", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", + "action": "Grenade", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "6d5d90a0-dded-4b6e-82fe-ba1431e2ada5", + "path": "/q", + "interactions": "", + "processors": "", + "groups": ";Keyboard_left", "action": "Grenade", "isComposite": false, "isPartOfComposite": false @@ -650,7 +749,7 @@ "path": "/w", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Navigate", "isComposite": false, "isPartOfComposite": true @@ -661,7 +760,7 @@ "path": "/upArrow", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Navigate", "isComposite": false, "isPartOfComposite": true @@ -672,7 +771,7 @@ "path": "/s", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Navigate", "isComposite": false, "isPartOfComposite": true @@ -683,7 +782,7 @@ "path": "/downArrow", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Navigate", "isComposite": false, "isPartOfComposite": true @@ -694,7 +793,7 @@ "path": "/a", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Navigate", "isComposite": false, "isPartOfComposite": true @@ -705,7 +804,7 @@ "path": "/leftArrow", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Navigate", "isComposite": false, "isPartOfComposite": true @@ -716,7 +815,7 @@ "path": "/d", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Navigate", "isComposite": false, "isPartOfComposite": true @@ -727,7 +826,7 @@ "path": "/rightArrow", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Navigate", "isComposite": false, "isPartOfComposite": true @@ -738,7 +837,7 @@ "path": "*/{Submit}", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse;Gamepad;Touch;Joystick;XR", + "groups": "Gamepad;Touch;Joystick;XR;Keyboard_right", "action": "Submit", "isComposite": false, "isPartOfComposite": false @@ -749,7 +848,7 @@ "path": "*/{Cancel}", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse;Gamepad;Touch;Joystick;XR", + "groups": "Gamepad;Touch;Joystick;XR;Keyboard_right", "action": "Cancel", "isComposite": false, "isPartOfComposite": false @@ -760,7 +859,7 @@ "path": "/position", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Point", "isComposite": false, "isPartOfComposite": false @@ -771,7 +870,7 @@ "path": "/position", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Point", "isComposite": false, "isPartOfComposite": false @@ -793,7 +892,7 @@ "path": "/leftButton", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Click", "isComposite": false, "isPartOfComposite": false @@ -804,7 +903,7 @@ "path": "/tip", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_right", "action": "Click", "isComposite": false, "isPartOfComposite": false @@ -837,7 +936,7 @@ "path": "/scroll", "interactions": "", "processors": "", - "groups": ";Keyboard&Mouse", + "groups": "Keyboard_right", "action": "ScrollWheel", "isComposite": false, "isPartOfComposite": false @@ -848,7 +947,7 @@ "path": "/rightButton", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "RightClick", "isComposite": false, "isPartOfComposite": false @@ -859,7 +958,7 @@ "path": "/middleButton", "interactions": "", "processors": "", - "groups": "Keyboard&Mouse", + "groups": "Keyboard_right", "action": "MiddleClick", "isComposite": false, "isPartOfComposite": false @@ -891,8 +990,8 @@ ], "controlSchemes": [ { - "name": "Keyboard&Mouse", - "bindingGroup": "Keyboard&Mouse", + "name": "Keyboard_right", + "bindingGroup": "Keyboard_right", "devices": [ { "devicePath": "", @@ -960,6 +1059,17 @@ "isOR": false } ] + }, + { + "name": "Keyboard_left", + "bindingGroup": "Keyboard_left", + "devices": [ + { + "devicePath": "", + "isOptional": false, + "isOR": false + } + ] } ] } \ No newline at end of file From 2769b3dc48e938568f537acb8653b1af5244871b Mon Sep 17 00:00:00 2001 From: pro2p Date: Wed, 6 May 2026 23:53:35 +0200 Subject: [PATCH 2/6] fix --- Assets/Game/Features/Input/EmptyInputProvider.cs | 1 - Assets/Game/Features/Input/IInputProvider.cs | 1 - Assets/Game/Features/Input/PlayerInputProvider.cs | 2 -- Assets/Game/Features/Tank/Tank.cs | 2 +- 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Assets/Game/Features/Input/EmptyInputProvider.cs b/Assets/Game/Features/Input/EmptyInputProvider.cs index f0929c4..445db53 100644 --- a/Assets/Game/Features/Input/EmptyInputProvider.cs +++ b/Assets/Game/Features/Input/EmptyInputProvider.cs @@ -2,7 +2,6 @@ { public class EmptyInputProvider : IInputProvider { - public bool IsTruePlayer() => false; public Vector2Int GetMilliAimingDir() => Vector2Int.Zero; public bool ShouldDash() => false; diff --git a/Assets/Game/Features/Input/IInputProvider.cs b/Assets/Game/Features/Input/IInputProvider.cs index 3414103..cabeb48 100644 --- a/Assets/Game/Features/Input/IInputProvider.cs +++ b/Assets/Game/Features/Input/IInputProvider.cs @@ -2,7 +2,6 @@ { public interface IInputProvider { - public bool IsTruePlayer(); public Vector2Int GetMilliMovementDir(); public Vector2Int GetMilliAimingDir(); public bool ShouldShoot(); diff --git a/Assets/Game/Features/Input/PlayerInputProvider.cs b/Assets/Game/Features/Input/PlayerInputProvider.cs index 88d0f7f..4508b6d 100644 --- a/Assets/Game/Features/Input/PlayerInputProvider.cs +++ b/Assets/Game/Features/Input/PlayerInputProvider.cs @@ -36,8 +36,6 @@ public PlayerInputProvider(PlayerInput playerInput) aimAction = playerInput.actions["Aim"]; } - public bool IsTruePlayer() => true; - public bool ShouldDash() => dashAction.IsPressed(); public bool ShouldGrenade() => grenadeAction.IsPressed(); diff --git a/Assets/Game/Features/Tank/Tank.cs b/Assets/Game/Features/Tank/Tank.cs index fd28e21..19d79ac 100644 --- a/Assets/Game/Features/Tank/Tank.cs +++ b/Assets/Game/Features/Tank/Tank.cs @@ -44,7 +44,7 @@ public override void Update() rigidbody.Velocity = movementInput * SPEED / 1000; Vector2Int directionInput = InputProvider.GetMilliAimingDir(); - if (InputProvider.IsTruePlayer() && ((PlayerInputProvider)InputProvider).PlayerControls == PlayerInputProvider.playerControlsType.Right) + if (InputProvider is PlayerInputProvider playerInputProvider && playerInputProvider.PlayerControls == PlayerInputProvider.playerControlsType.Right) { directionInput = new Vector2Int(directionInput.X - Position.X, directionInput.Y - Position.Y); } From 931f39b43b98d515da3d8ac25476346cce87c9d8 Mon Sep 17 00:00:00 2001 From: pro2p Date: Wed, 6 May 2026 23:55:36 +0200 Subject: [PATCH 3/6] fix --- Assets/Game/Features/Input/PlayerInputProvider.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Assets/Game/Features/Input/PlayerInputProvider.cs b/Assets/Game/Features/Input/PlayerInputProvider.cs index 4508b6d..2a1ca1c 100644 --- a/Assets/Game/Features/Input/PlayerInputProvider.cs +++ b/Assets/Game/Features/Input/PlayerInputProvider.cs @@ -6,8 +6,8 @@ namespace Automathon.Game.Input { public class PlayerInputProvider : IInputProvider { - public enum playerControlsType { Left, Right, Gamepad } - public playerControlsType PlayerControls { get; private set; } + public enum PlayerControlsType { Left, Right, Gamepad } + public PlayerControlsType PlayerControls { get; private set; } private InputAction dashAction; private InputAction grenadeAction; private InputAction shieldAction; @@ -18,15 +18,15 @@ public PlayerInputProvider(PlayerInput playerInput) { if (playerInput.currentControlScheme == "Gamepad") { - PlayerControls = playerControlsType.Gamepad; + PlayerControls = PlayerControlsType.Gamepad; } else if (playerInput.currentControlScheme == "Keyboard_left") { - PlayerControls = playerControlsType.Left; + PlayerControls = PlayerControlsType.Left; } else if (playerInput.currentControlScheme == "Keyboard_right") { - PlayerControls = playerControlsType.Right; + PlayerControls = PlayerControlsType.Right; } dashAction = playerInput.actions["Dash"]; grenadeAction = playerInput.actions["Grenade"]; From 9fe62a666b5f9522d739c60efbb5ceb66b649495 Mon Sep 17 00:00:00 2001 From: pro2p Date: Wed, 6 May 2026 23:59:06 +0200 Subject: [PATCH 4/6] fix --- Assets/Game/Features/Input/PlayerInputProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Game/Features/Input/PlayerInputProvider.cs b/Assets/Game/Features/Input/PlayerInputProvider.cs index 2a1ca1c..ed3b1e8 100644 --- a/Assets/Game/Features/Input/PlayerInputProvider.cs +++ b/Assets/Game/Features/Input/PlayerInputProvider.cs @@ -53,7 +53,7 @@ public Vector2Int GetMilliMovementDir() public Vector2Int GetMilliAimingDir() { Vector2 aimingDir = aimAction.ReadValue(); - if (PlayerControls == playerControlsType.Right) + if (PlayerControls == PlayerControlsType.Right) { Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(aimingDir.x, aimingDir.y, WorldConstants.CAMERA_DISTANCE / 1000)); return new Vector2Int((int)(worldPos.x * WorldConstants.SPACE_SCALE), (int)(worldPos.y * WorldConstants.SPACE_SCALE)); From 80c3a5c6809cc61c271d22331c7eb3b2e3b6f8ed Mon Sep 17 00:00:00 2001 From: pro2p Date: Thu, 7 May 2026 00:06:55 +0200 Subject: [PATCH 5/6] fiiiix --- Assets/Game/Features/Lobby/TankSpawnerView.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Game/Features/Lobby/TankSpawnerView.cs b/Assets/Game/Features/Lobby/TankSpawnerView.cs index 1d1d96f..e8978a7 100644 --- a/Assets/Game/Features/Lobby/TankSpawnerView.cs +++ b/Assets/Game/Features/Lobby/TankSpawnerView.cs @@ -30,12 +30,12 @@ private void Update() { if (Keyboard.current.escapeKey.wasPressedThisFrame || Keyboard.current.deleteKey.wasPressedThisFrame) { - bool left = Keyboard.current.escapeKey.wasPressedThisFrame; + bool isLeftPlayer = Keyboard.current.escapeKey.wasPressedThisFrame; PlayerInput playerInputToRemove = null; foreach (PlayerInput playerInput in inputProviders.Keys) { - if ((left && playerInput.currentControlScheme == "Keyboard_left") || (!left && playerInput.currentControlScheme == "Keyboard_right")) + if ((isLeftPlayer && playerInput.currentControlScheme == "Keyboard_left") || (!isLeftPlayer && playerInput.currentControlScheme == "Keyboard_right")) { playerInputToRemove = playerInput; break; From 1bcd70b140b3c24a7499d65fa89af6c87f802b99 Mon Sep 17 00:00:00 2001 From: pro2p Date: Wed, 13 May 2026 13:36:12 +0200 Subject: [PATCH 6/6] outsource view-related calculations and replace if-else by dictionary acces --- .../Features/Input/PlayerInputProvider.cs | 32 +++++++++---------- Assets/Game/Features/Utility/ViewMath.cs | 4 +++ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Assets/Game/Features/Input/PlayerInputProvider.cs b/Assets/Game/Features/Input/PlayerInputProvider.cs index ed3b1e8..a61dd87 100644 --- a/Assets/Game/Features/Input/PlayerInputProvider.cs +++ b/Assets/Game/Features/Input/PlayerInputProvider.cs @@ -1,4 +1,5 @@ -using Automathon.Game.World; +using Automathon.Utility; +using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; @@ -6,7 +7,7 @@ namespace Automathon.Game.Input { public class PlayerInputProvider : IInputProvider { - public enum PlayerControlsType { Left, Right, Gamepad } + public enum PlayerControlsType { LeftKeyboard, RightKeyboard, Gamepad } public PlayerControlsType PlayerControls { get; private set; } private InputAction dashAction; private InputAction grenadeAction; @@ -14,20 +15,17 @@ public enum PlayerControlsType { Left, Right, Gamepad } private InputAction shootAction; private InputAction moveAction; private InputAction aimAction; + + private Dictionary schemeToControlsType = new Dictionary + { + { "Gamepad", PlayerControlsType.Gamepad }, + { "Keyboard_left", PlayerControlsType.LeftKeyboard }, + { "Keyboard_right", PlayerControlsType.RightKeyboard } + }; + public PlayerInputProvider(PlayerInput playerInput) { - if (playerInput.currentControlScheme == "Gamepad") - { - PlayerControls = PlayerControlsType.Gamepad; - } - else if (playerInput.currentControlScheme == "Keyboard_left") - { - PlayerControls = PlayerControlsType.Left; - } - else if (playerInput.currentControlScheme == "Keyboard_right") - { - PlayerControls = PlayerControlsType.Right; - } + PlayerControls = schemeToControlsType[playerInput.currentControlScheme]; dashAction = playerInput.actions["Dash"]; grenadeAction = playerInput.actions["Grenade"]; shieldAction = playerInput.actions["Shield"]; @@ -53,10 +51,10 @@ public Vector2Int GetMilliMovementDir() public Vector2Int GetMilliAimingDir() { Vector2 aimingDir = aimAction.ReadValue(); - if (PlayerControls == PlayerControlsType.Right) + if (PlayerControls == PlayerControlsType.RightKeyboard) { - Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(aimingDir.x, aimingDir.y, WorldConstants.CAMERA_DISTANCE / 1000)); - return new Vector2Int((int)(worldPos.x * WorldConstants.SPACE_SCALE), (int)(worldPos.y * WorldConstants.SPACE_SCALE)); + Vector3 worldPos = aimingDir.ScreenToWorldSpace(); + return ((Vector2)worldPos).ToVector2IntScaled(); } return new Vector2Int((int)(aimingDir.x * 1000), (int)(aimingDir.y * 1000)); } diff --git a/Assets/Game/Features/Utility/ViewMath.cs b/Assets/Game/Features/Utility/ViewMath.cs index a6de619..68021af 100644 --- a/Assets/Game/Features/Utility/ViewMath.cs +++ b/Assets/Game/Features/Utility/ViewMath.cs @@ -1,3 +1,4 @@ +using Automathon.Game.World; using UnityEngine; namespace Automathon.Utility @@ -8,5 +9,8 @@ public static Quaternion MilliRadRotationToQuaternion(float rotationMillirad) { return Quaternion.Euler(0, 0, rotationMillirad * Mathf.Rad2Deg / 1000f); } + + public static Vector2Int ToVector2IntScaled(this Vector2 vector) + => new Vector2Int((int)(vector.x * WorldConstants.SPACE_SCALE), (int)(vector.y * WorldConstants.SPACE_SCALE)); } }