{"comment":{"url":"https://api.github.com/repos/MayBGames/babbling-on/comments/27482742","html_url":"https://github.com/MayBGames/babbling-on/commit/913ba45d210664fc9faf26b5983dee390639f18b#commitcomment-27482742","id":27482742,"user":{"login":"bsgbryan","id":30052,"avatar_url":"https://avatars0.githubusercontent.com/u/30052?v=4","gravatar_id":"","url":"https://api.github.com/users/bsgbryan","html_url":"https://github.com/bsgbryan","followers_url":"https://api.github.com/users/bsgbryan/followers","following_url":"https://api.github.com/users/bsgbryan/following{/other_user}","gists_url":"https://api.github.com/users/bsgbryan/gists{/gist_id}","starred_url":"https://api.github.com/users/bsgbryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsgbryan/subscriptions","organizations_url":"https://api.github.com/users/bsgbryan/orgs","repos_url":"https://api.github.com/users/bsgbryan/repos","events_url":"https://api.github.com/users/bsgbryan/events{/privacy}","received_events_url":"https://api.github.com/users/bsgbryan/received_events","type":"User","site_admin":false},"position":119,"line":127,"path":"src/movement.js","commit_id":"913ba45d210664fc9faf26b5983dee390639f18b","created_at":"2018-02-11T05:18:27Z","updated_at":"2018-02-11T05:18:27Z","author_association":"COLLABORATOR","body":"### Pattern\r\n\r\nThe above lines break down to the following pattern:\r\n\r\n1. Determine what direction `key` is pressed\r\n2. Check that the value for `key` in `keys_down` is greater than zero, and less that 50 (_the max rate of movement_)\r\n3. If that fails, check that the value for `key` in `keys_down` is `undefined`\r\n4. If the value for `key` in `keys_down` is `undefined`, check that the value for `key` in `keys_down` is greater/less than zero\r\n\r\n### 3D Coordinate System\r\n\r\nBabylon.js' coordinate system is different from the coordinate systems used by other 3D tools in that `y` describes vertical positions. Other 3D tools use `z` to describe vertical positions.\r\n\r\nAside from that Babylon.js' coordinate system is pretty standard:\r\n\r\n* `x` describes positions left or right of the origin\r\n* `z` describes positions in front of or behind the origin (_in other 3D tools `y` describes this_)\r\n\r\n![y up/down, x left/right, z forward/backward](http://what-when-how.com/wp-content/uploads/2011/08/tmpD53_thumb.jpg \"Babylon's 3D Coordinate System\")\r\n\r\n##### What's an origin\r\n\r\nIn any coordinate system where values can be positive or negative values can also be zero.\r\n\r\nThe place where `x`, `y`, and `z` all have zero values is called the **origin**. You can think of the origin as the center of your game's world.\r\n\r\n### Step 1\r\n\r\nStep 1 is pretty self explanatory and straight forward. Line 97 checks which of the four options (_`FORWARD`, `BACKWARD`, `LEFT`, `RIGHT`_) `key` is. The `case` statements then execute a chunk of code based on the value of `key`. You can get more info on switch statements [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch).\r\n\r\n### Step 2\r\n\r\nIf this check passes the player character is moving in a direction and has not yet hit max velocity.\r\n\r\n##### FORWARD\r\n\r\nIf the `FORWARD` key is pressed and `distance_per_second.z` (_the distance the player character moves along `z` in one second_) is less than 50 (_the max movement speed_) then `distance_per_second.z` gets incremented by one. Changing `z` changes the speed at which the player character moves along `z`. Increasing `z` by one causes the player character to move faster along `z` in the positive (_forward_) direction.\r\n\r\nIf the `FORWARD` key is not pressed and `distance_per_second.z` is greater than zero, 1 is subtracted from `z`. This causes the player character to move more slowly along `z`, until they are no longer moving at all.\r\n\r\n##### BACKWARD\r\n\r\nThis case is identical to the `FORWARD` case, just reversed."}}
{"actor":{"display_login":"bsgbryan"}}