Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player physics improvements #6

Merged
merged 6 commits into from
Oct 30, 2024
Merged

Player physics improvements #6

merged 6 commits into from
Oct 30, 2024

Conversation

wjt
Copy link
Member

@wjt wjt commented Oct 25, 2024

This adds a few nice adjustments to the player controls:

  • You get a few frames' grace after walking off a ledge where you can still jump ("coyote time")
  • You get a few frames' grace if you press jump just before the character lands from a previous jump/fall ("jump buffering")
  • You can control the height of the jump by releasing the jump key before the player reaches the top of the arc and starts descending ("jump cut")
  • The player accelerates (over about 5 frames by default) when pressing or releasing left or right, rather than the velocity being set immediately. The acceleration can be controlled by the learner in the inspector.
  • The player can now optionally double-jump.

I think this feels a bit nicer to play (though the jump is still a bit "floaty" for my liking). I would want learning team feedback on whether these tweaks are helpful or whether they complicate the example too much. They were fun to write though.

https://phabricator.endlessm.com/T35700

Screencast.from.2024-10-25.14-47-16.webm

@wjt wjt force-pushed the player-physics-improvements branch 3 times, most recently from b126576 to fbbf891 Compare October 25, 2024 19:21
## How high does your character jump? Note that the gravity will
## be influenced by the [member GameLogic.gravity].
@export_range(-1000, 1000, 10, "suffix:px/s") var jump_velocity = -880.0

## Can your character jump a second time while still in the air?
@export var double_jump: bool = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I love that these platformer settings are part of the "moddability" (if that's a word in English).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

descriptivism tells us that if it's a word people use and understand, then it's a word :)

@export var double_jump: bool = false

# If positive, the player is either on the ground, or left the ground less than this long ago
var coyote_timer: float = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can coyote timer be turned on/off or configured from the Inspector? See https://gmtk.itch.io/platformer-toolkit for reference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't make coyote time or jump buffering configurable in the inspector because they're quite non-obvious parameters with a very narrow range of sensible settings. But maybe it's OK to expose them anyway with a good tooltip, maybe in an "advanced" group.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made these configurable, as a slider whose steps are frame durations @ 60 fps, with 0 turning them off.

@wjt wjt force-pushed the player-physics-improvements branch from fbbf891 to 0782e47 Compare October 26, 2024 08:45
@wjt
Copy link
Member Author

wjt commented Oct 26, 2024

I made coyote time, jump buffering and jump cut configurable:

image

@wjt wjt force-pushed the player-physics-improvements branch from 0782e47 to c6bce4e Compare October 26, 2024 08:47
This technique is borrowed from the MOVEMENT 2 demo available in the Godot
Asset Library. It makes jumping feel a little more natural: you can do a little
jump by tapping space, or a long jump by holding it a little longer.
It is common in platform games to allow the player a few frames' grace after
walking off the edge of a ledge where they can still jump as if they were still
standing on the ledge.

This technique is inspired by the MOVEMENT 2 demo available in the Asset
Library.
Previously, you could only jump if you were already on the ground when you
press the jump button. This seems logical but is actually very annoying: if you
press jump 1 frame too early, then you miss.

It is common in platformers to allow a few frames' grace, so that you can press
the jump key a few frames early and still start a jump when the player touches
the ground. To implement this, count down from 0.1s (6 ticks at the default 60
ticks per second) when the jump action is just pressed.

This technique is borrowed from MOVEMENT 2.
With the defaults it takes 5 frames to accelerate to the maximum speed.
@wjt wjt force-pushed the player-physics-improvements branch from c6bce4e to f9e6615 Compare October 26, 2024 08:48
If enabled, the player can jump a second time while still in the air from a
previous jump. A crude shower of particles is emitted to indicate ✨ magic ✨.
Previously, when the player stomped an enemy the enemy would set the
player's vertical velocity directly.

Instead, have the enemy call a new stomp() method on the player, which
internally triggers a jump having disarmed the double-jump. This makes a
difference in the following cases:

- If the player has a jump buffered, stomping on the enemy now consumes
  that jump.
- If the player is holding the jump key (because they buffered a jump)
  they can curtail the height of bouncing off the enemy.
- If double jump is enabled, it is now armed by stomping an enemy.
@wjt wjt force-pushed the player-physics-improvements branch from f9e6615 to b14ffa8 Compare October 26, 2024 08:56
@manuq
Copy link
Contributor

manuq commented Oct 28, 2024

I gave it a try, it's impressive and moddable!

@wjt wjt marked this pull request as ready for review October 30, 2024 11:01
@wjt
Copy link
Member Author

wjt commented Oct 30, 2024

@jbourqueendless gave the thumbs-up to the concept on Slack so I'm undrafting this

@manuq manuq merged commit 3dce3a1 into main Oct 30, 2024
1 check passed
@manuq manuq deleted the player-physics-improvements branch October 30, 2024 12:56
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.

2 participants