Skip to content

Instantly share code, notes, and snippets.

@waimus
Created August 23, 2022 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waimus/d7842166f44086041af878c1fb639ea0 to your computer and use it in GitHub Desktop.
Save waimus/d7842166f44086041af878c1fb639ea0 to your computer and use it in GitHub Desktop.
The idea is to have easy jump and quick fall. E.g. by lowering the gravity during jump and doubling the gravity during fall (which detected by `velocity.y < 0`).
# No warranty to immediately work. May need additional configuration
export(float) var jump_height : float = 64.0
var world_gravity : Vector3 = Vector3.DOWN * 10.0
var move_velocity : Vector3 = Vector3.ZERO
# Handle player jump movement implenented with KinematicBody
func action_input_jump(delta : float) -> void:
world_gravity = Vector3.DOWN * 10
move_velocity += world_gravity * delta
# Read input action name "cl_move_up"
if Input.is_action_just_pressed("cl_move_up"):
if self.is_on_floor():
move_velocity.y = jump_height
if !self.is_on_floor() and move_velocity.y < 0:
world_gravity = Vector3.DOWN * 256
move_velocity = move_and_slide(move_velocity, Vector3.UP, true, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment