Always teleport full distance, even with analogue stick input#91
Draft
wjt wants to merge 1 commit into
Draft
Conversation
Member
Author
|
Eagle-eyed viewers on today's Loom Lounge may have spotted me discovering and fixing this bug. @jgbourque I think this is obscure enough that we shouldn't leave it as a bug for learners to find & potentially exploit? |
|
Play this branch at https://endlessm.github.io/moddable-platformer/branches/endlessm/wjt/teleport-distance-signf/. (This launches the game from the start, not directly at the change(s) in this pull request.) |
_teleport() takes an input_direction in range [-1, 1] as input, and if it is not approximately zero, teleports the player by input_direction * TELEPORT_DISTANCE. The direction comes from: var direction = Input.get_axis(Actions.lookup(player, "left"), Actions.lookup(player, "right")) When using keyboard or D-pad input, this is always -1, 0, or 1. But with an analogue joystick it can be any value between -1 and 1. (Actually strictly speaking it can be [-1.0, -0.5], 0, or [0.5, 1.0] because the left/right actions' dead zones are set to 0.5.) Use signf to round any negative value to -1 and any positive value to 1 when calculating how far to teleport the player.
4e28e10 to
4d605a3
Compare
Member
Author
|
I pushed a second version that adds a huge comment explaining what |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_teleport() takes an input_direction in range [-1, 1] as input, and if it is not approximately zero, teleports the player by input_direction * TELEPORT_DISTANCE.
The direction comes from:
When using keyboard or D-pad input, this is always -1, 0, or 1. But with an analogue joystick it can be any value between -1 and 1. (Actually strictly speaking it can be [-1.0, -0.5], 0, or [0.5, 1.0] because the left/right actions' dead zones are set to 0.5.)
Use signf to round any negative value to -1 and any positive value to 1 when calculating how far to teleport the player.