Flopsy/objects/characters/character.gd

37 lines
818 B
GDScript

extends KinematicBody2D
var velocity = Vector2(0, 0)
var snap = Vector2.ZERO
var last_time_on_floor : int = 0
func _ready():
_enable_snap()
func _process_gravity(delta):
if not is_on_floor():
if last_time_on_floor == 0:
last_time_on_floor = OS.get_ticks_msec()
velocity.y += GlobalConfig.GRAVITY.y * delta
else:
last_time_on_floor = 0
_enable_snap()
velocity.y = 0
if is_on_ceiling():
velocity.y = 1
func _physics_process(delta):
move_and_slide_with_snap(velocity, snap, Vector2.UP)
_process_gravity(delta)
func _disable_snap():
snap = Vector2.ZERO
func _enable_snap():
snap = GlobalConfig.SNAP
func _check_jump():
print(OS.get_ticks_msec() - last_time_on_floor)
if last_time_on_floor == 0:
return true
return OS.get_ticks_msec() - last_time_on_floor <= GlobalConfig.JUMP_COYOTE