Skip to content

Always teleport full distance, even with analogue stick input - #91

Merged
wjt merged 1 commit into
mainfrom
wjt/teleport-distance-signf
Jul 28, 2026
Merged

Always teleport full distance, even with analogue stick input#91
wjt merged 1 commit into
mainfrom
wjt/teleport-distance-signf

Conversation

@wjt

@wjt wjt commented May 22, 2026

Copy link
Copy Markdown
Member

_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.

@wjt
wjt requested a review from a team as a code owner May 22, 2026 19:03
@wjt
wjt marked this pull request as draft May 22, 2026 19:03
@wjt

wjt commented May 22, 2026

Copy link
Copy Markdown
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?

@github-actions

Copy link
Copy Markdown

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.)

@wjt
wjt force-pushed the wjt/teleport-distance-signf branch from 4e28e10 to 4d605a3 Compare May 22, 2026 19:05
@wjt

wjt commented May 22, 2026

Copy link
Copy Markdown
Member Author

I pushed a second version that adds a huge comment explaining what signf() does. But I think this detracts from the simplicity of the function...

@wjt
wjt marked this pull request as ready for review June 11, 2026 12:59
@wjt
wjt force-pushed the wjt/teleport-distance-signf branch from 4d605a3 to 1fd0e1d Compare June 23, 2026 08:16
@wjt

wjt commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

@jgbourque says:

i never tried [teleporting with a joystick]! if it plays really weird, I'd just fix it. yeah, I agree its a bit obscure.

@wjt
wjt force-pushed the wjt/teleport-distance-signf branch from 1fd0e1d to 2d9a7d7 Compare July 28, 2026 13:40
_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.
@wjt
wjt force-pushed the wjt/teleport-distance-signf branch from 2d9a7d7 to 1728244 Compare July 28, 2026 13:42
@wjt

wjt commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

I simplified it back to just the fix without further comment.

@wjt
wjt merged commit 607343f into main Jul 28, 2026
1 check passed
@wjt
wjt deleted the wjt/teleport-distance-signf branch July 28, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant