Fixed Bug where WASD Movement worked when focused on Chat Input

This commit is contained in:
pelpanagiotis
2026-02-04 22:39:40 +02:00
parent 1a564d392a
commit 9bcb47d8f6
18 changed files with 182 additions and 1903 deletions

View File

@@ -81,6 +81,12 @@ public class CharacterMovement : NetworkBehaviour
if (kb.dKey.isPressed) keyboardMovement.x += 1f;
}
// Disable keyboard WASD while typing in chat input
if (ChatUI.IsInputFieldFocused)
{
keyboardMovement = Vector2.zero;
}
// combine input action movement and keyboard movement
combinedMovement = currentMovement + keyboardMovement;
// prevent faster diagonal movement

View File

@@ -15,11 +15,16 @@ public class ChatUI : MonoBehaviour
internal static string localPlayerName;
// Instance reference so static callers can check focus state safely
internal static ChatUI Instance;
private readonly List<string> lines = new();
private Player localPlayer;
void Awake()
{
Instance = this;
if (chatMessage != null)
{
chatMessage.onValueChanged.AddListener(ToggleButton);
@@ -27,6 +32,9 @@ public class ChatUI : MonoBehaviour
}
}
// Expose whether the chat input is focused so other systems can disable input/movement
public static bool IsInputFieldFocused => Instance != null && Instance.chatMessage != null && Instance.chatMessage.isFocused;
// Called by Player.OnStartLocalPlayer to connect the UI to the player's network methods.
public void Initialize(Player player)
{
@@ -102,6 +110,12 @@ public class ChatUI : MonoBehaviour
void OnDestroy()
{
if (chatMessage != null)
{
chatMessage.onValueChanged.RemoveListener(ToggleButton);
chatMessage.onSubmit.RemoveListener(OnInputSubmit);
}
// Clear static instance reference
if (Instance == this) Instance = null;
}
}

View File

@@ -90,6 +90,15 @@ namespace QuickStart
return;
}
// If the chat input is focused, skip movement input to avoid moving while typing.
// Still keep the floating info facing the camera for readability.
if (ChatUI.IsInputFieldFocused)
{
if (Camera.main != null)
floatingInfo.transform.LookAt(Camera.main.transform);
return;
}
float rotationDelta = 0f;
float forwardDelta = 0f;