Add jump buffering to player slime.
This commit is contained in:
parent
46cac1e3c7
commit
696a89d1ec
1 changed files with 16 additions and 2 deletions
|
|
@ -3,6 +3,12 @@ extends CharacterBody2D
|
||||||
const MOVE_SPEED = 200.0
|
const MOVE_SPEED = 200.0
|
||||||
const CLIMB_SPEED = -150.0
|
const CLIMB_SPEED = -150.0
|
||||||
const JUMP_VELOCITY = -250.0
|
const JUMP_VELOCITY = -250.0
|
||||||
|
|
||||||
|
# Time window (in seconds) on when to auto-jump when pressing jump key
|
||||||
|
# before landing on the ground.
|
||||||
|
const TOTAL_JUMP_BUFFER_S = 0.1
|
||||||
|
var jumpBufferTimeLeft = 0.0
|
||||||
|
|
||||||
const WALL_SLIDE_MODIFIER = 0.1
|
const WALL_SLIDE_MODIFIER = 0.1
|
||||||
const ROTATE_TO_WALL_SPEED = 25 # How quickly to rotate the sprite when clinging to a wall.
|
const ROTATE_TO_WALL_SPEED = 25 # How quickly to rotate the sprite when clinging to a wall.
|
||||||
|
|
||||||
|
|
@ -34,9 +40,17 @@ func _physics_process(delta: float) -> void:
|
||||||
elif not is_on_floor():
|
elif not is_on_floor():
|
||||||
velocity.y += get_gravity().y * delta
|
velocity.y += get_gravity().y * delta
|
||||||
|
|
||||||
# Handle jump.
|
# Jumping! And also jump buffering.
|
||||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
if Input.is_action_just_pressed("jump") and not (is_on_floor() or is_on_wall()):
|
||||||
|
jumpBufferTimeLeft = TOTAL_JUMP_BUFFER_S
|
||||||
|
print("start jump buffer")
|
||||||
|
|
||||||
|
if ((Input.is_action_just_pressed("jump") or jumpBufferTimeLeft > 0.0)
|
||||||
|
and is_on_floor()):
|
||||||
velocity.y = JUMP_VELOCITY
|
velocity.y = JUMP_VELOCITY
|
||||||
|
jumpBufferTimeLeft = 0.0
|
||||||
|
if jumpBufferTimeLeft > 0.0:
|
||||||
|
jumpBufferTimeLeft -= delta
|
||||||
|
|
||||||
# Quick setup for oozing up walls
|
# Quick setup for oozing up walls
|
||||||
if verticalInput > 0 and is_on_wall():
|
if verticalInput > 0 and is_on_wall():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue