Always teleport full distance, even with analogue stick input - #91
Conversation
|
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.) |
4e28e10 to
4d605a3
Compare
|
I pushed a second version that adds a huge comment explaining what |
4d605a3 to
1fd0e1d
Compare
|
@jgbourque says:
|
1fd0e1d to
2d9a7d7
Compare
_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.
2d9a7d7 to
1728244
Compare
|
I simplified it back to just the fix without further comment. |
_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.