master #5
@ -1,11 +1,11 @@
|
|||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
const SPEED = 300.0
|
const SPEED = 300.0
|
||||||
const JUMP_VELOCITY = -600.0
|
const JUMP_VELOCITY = -1000.0
|
||||||
const MAX_JUMP_DURATION = 0.3
|
const MAX_JUMP_DURATION = 0.3
|
||||||
const MIN_JUMP_DURATION = 0.1
|
const MIN_JUMP_DURATION = 0.01
|
||||||
const GRAVITY = 980
|
const GRAVITY = 980
|
||||||
const FALL_GRAVITY_MULTIPLIER = 1.5
|
const FALL_GRAVITY_MULTIPLIER = 2
|
||||||
|
|
||||||
var jump_timer = 0.0
|
var jump_timer = 0.0
|
||||||
var is_jumping = false
|
var is_jumping = false
|
||||||
@ -13,7 +13,7 @@ var is_jumping = false
|
|||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
# Apply gravity
|
# Apply gravity
|
||||||
if not is_on_floor():
|
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
|
velocity.y += GRAVITY * gravity_multiplier * delta
|
||||||
|
|
||||||
# Handle Jump
|
# Handle Jump
|
||||||
@ -21,8 +21,7 @@ func _physics_process(delta):
|
|||||||
start_jump()
|
start_jump()
|
||||||
|
|
||||||
if is_jumping:
|
if is_jumping:
|
||||||
jump_timer += delta
|
if Input.is_action_pressed("jump"):
|
||||||
if Input.is_action_pressed("jump") and jump_timer < MAX_JUMP_DURATION:
|
|
||||||
continue_jump(delta)
|
continue_jump(delta)
|
||||||
else:
|
else:
|
||||||
end_jump()
|
end_jump()
|
||||||
@ -39,15 +38,11 @@ func _physics_process(delta):
|
|||||||
func start_jump():
|
func start_jump():
|
||||||
velocity.y = JUMP_VELOCITY
|
velocity.y = JUMP_VELOCITY
|
||||||
is_jumping = true
|
is_jumping = true
|
||||||
jump_timer = 0.0
|
|
||||||
|
|
||||||
func continue_jump(delta):
|
func continue_jump(delta):
|
||||||
if jump_timer > MIN_JUMP_DURATION:
|
pass
|
||||||
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
|
|
||||||
|
|
||||||
func end_jump():
|
func end_jump():
|
||||||
is_jumping = false
|
|
||||||
if velocity.y < 0:
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user