Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMD Key Issue with useKeyboardControls in Player Component #76

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AlexMubarakshin
Copy link

@AlexMubarakshin AlexMubarakshin commented Jun 22, 2024

While exploring the useKeyboardControls hook from react-three/drei for Player component, I discovered an issue exclusive to macOS users. The hook fails to ignore the CMD key, leading to a scenario where the character begins to move non-stop in one direction after a player uses a combination of the CMD key and a movement key (e.g., CMD+S for fullscreen). This behavior disrupts the gameplay experience and conflicts with common macOS shortcuts, causing unexpected and confusing behavior for the players.

Steps to Reproduce

  1. Press and hold CMD (on macOS) and then press one of the movement keys (e.g., arrow keys or WASD).
  2. Release both keys.
  3. Observe that the character continues to move in the direction of the movement key pressed, without stopping.

Solution and Implementation

To address this issue, I added a feature to the custom hook that intercepts and processes keyboard events, explicitly ignoring any inputs involving the CMD key. Additionally, the hook resets the controls state whenever the CMD key is pressed, immediately halting any ongoing movement commands. This ensures the character does not move indefinitely, allowing macOS users to use system shortcuts without triggering continuous movement in the game.

This commit enhances the keyboard controls within the Player component, specifically addressing an issue where the combination of CMD (on macOS) or Control (on other platforms) keys with movement keys (e.g., arrow keys) did not function as expected. The update ensures a smoother and more intuitive control scheme for users, facilitating better gameplay experience by allowing simultaneous use of command keys with movement controls.
@CLAassistant
Copy link

CLAassistant commented Jun 22, 2024

CLA assistant check
All committers have signed the CLA.

@AlexMubarakshin AlexMubarakshin changed the title Fix CMD Key Issue with useKeyboardControls in Player Component DRAFT: Fix CMD Key Issue with useKeyboardControls in Player Component Jun 22, 2024
Reset the state of keyboard controls when the meta key (CMD on macOS) is pressed.
@AlexMubarakshin AlexMubarakshin changed the title DRAFT: Fix CMD Key Issue with useKeyboardControls in Player Component Fix CMD Key Issue with useKeyboardControls in Player Component Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants