tuned jumping

This commit is contained in:
Egg Man 2024-09-07 12:21:36 -04:00
parent 0f41e0d017
commit 709cee6893

View File

@ -1,11 +1,11 @@
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -600.0
const JUMP_VELOCITY = -1000.0
const MAX_JUMP_DURATION = 0.3
const MIN_JUMP_DURATION = 0.1
const MIN_JUMP_DURATION = 0.01
const GRAVITY = 980
const FALL_GRAVITY_MULTIPLIER = 1.5
const FALL_GRAVITY_MULTIPLIER = 2
var jump_timer = 0.0
var is_jumping = false
@ -13,7 +13,7 @@ var is_jumping = false
func _physics_process(delta):
# Apply gravity
if not is_on_floor():
var gravity_multiplier = FALL_GRAVITY_MULTIPLIER if velocity.y > 0 else 1.0
var gravity_multiplier = FALL_GRAVITY_MULTIPLIER if velocity.y > 0 else 2
velocity.y += GRAVITY * gravity_multiplier * delta
# Handle Jump
@ -21,8 +21,7 @@ func _physics_process(delta):
start_jump()
if is_jumping:
jump_timer += delta
if Input.is_action_pressed("jump") and jump_timer < MAX_JUMP_DURATION:
if Input.is_action_pressed("jump"):
continue_jump(delta)
else:
end_jump()
@ -39,15 +38,11 @@ func _physics_process(delta):
func start_jump():
velocity.y = JUMP_VELOCITY
is_jumping = true
jump_timer = 0.0
func continue_jump(delta):
if jump_timer > MIN_JUMP_DURATION:
var t = (jump_timer - MIN_JUMP_DURATION) / (MAX_JUMP_DURATION - MIN_JUMP_DURATION)
var ease_factor = 1.0 - t * t # Quadratic easing
velocity.y += JUMP_VELOCITY * ease_factor * delta
pass
func end_jump():
is_jumping = false
if velocity.y < 0:
velocity.y *= 0.5 # Cut the upward velocity to end the jump early if button is released
velocity.y *= 0.20
is_jumping = false