Skip to content

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

Draft
wjt wants to merge 1 commit into
mainfrom
wjt/teleport-distance-signf
Draft

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

Conversation

@wjt
Copy link
Copy Markdown
Member

@wjt wjt commented May 22, 2026

_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
Copy link
Copy Markdown
Member Author

wjt commented May 22, 2026

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

_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 4e28e10 to 4d605a3 Compare May 22, 2026 19:05
@wjt
Copy link
Copy Markdown
Member Author

wjt commented May 22, 2026

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

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