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

demo/client: Make WASD composable #32

Merged
merged 1 commit into from Sep 19, 2017
Merged

demo/client: Make WASD composable #32

merged 1 commit into from Sep 19, 2017

Conversation

@Manishearth
Copy link
Member

Manishearth commented Sep 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.

@Manishearth Manishearth force-pushed the Manishearth:wasd branch from b88d6dc to 4466446 Sep 19, 2017
@@ -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.

@pcwalton

pcwalton Sep 19, 2017

Collaborator

nit: no need for parens around (x)

private updateMovementDelta(): boolean {
this.movementDelta = glmatrix.vec3.create();
let empty = true;
for (let key of KEYCODES) {

This comment has been minimized.

@pcwalton

pcwalton Sep 19, 2017

Collaborator

nit: this can be const

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.
@Manishearth Manishearth force-pushed the Manishearth:wasd branch from 4466446 to 9a0fa96 Sep 19, 2017
@pcwalton pcwalton merged commit b1cf4b9 into servo:master Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.