Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign updemo/client: Make WASD composable #32
Merged
Conversation
demo/client/src/camera.ts
Outdated
| @@ -42,6 +42,8 @@ const PERSPECTIVE_INITIAL_ROTATION: glmatrix.vec2 = glmatrix.vec2.clone([Math.PI | |||
| const PERSPECTIVE_OUTER_COLLISION_EXTENT: number = 3000.0; | |||
| const PERSPECTIVE_HITBOX_RADIUS: number = 1.0; | |||
|
|
|||
| const KEYCODES = ["W", "A", "S", "D"].map((x) => x.charCodeAt(0)); | |||
This comment has been minimized.
This comment has been minimized.
demo/client/src/camera.ts
Outdated
| private updateMovementDelta(): boolean { | ||
| this.movementDelta = glmatrix.vec3.create(); | ||
| let empty = true; | ||
| for (let key of KEYCODES) { |
This comment has been minimized.
This comment has been minimized.
Currently movement works in the direction of the latest key pressed. Moving diagonally is not possible, and if you are pressing two keys and release one, movement stops instead of switching over. This keeps track of the key press state and updates the movement delta accordingly, leading to much more natural/pleasant WASD navigation. Note than onKeyDown is called multiple times when you press and hold, so we must keep track of this state ourselves.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Manishearth commentedSep 19, 2017
Currently movement works in the direction of the latest key pressed.
Moving diagonally is not possible, and if you are pressing two keys
and release one, movement stops instead of switching over.
This keeps track of the key press state and updates the movement delta
accordingly.
Note than onKeyDown is called multiple times when you press and hold,
so we must keep track of this state ourselves.