From be7e809a7c4a9df2b64b1fc5d6e939c0c5b9f448 Mon Sep 17 00:00:00 2001 From: nokoe Date: Tue, 6 Aug 2024 21:42:01 +0200 Subject: smooth scrolling --- client/menu/scroll_container_custom.gd | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'client/menu') diff --git a/client/menu/scroll_container_custom.gd b/client/menu/scroll_container_custom.gd index 4908299e..b3ce4e46 100644 --- a/client/menu/scroll_container_custom.gd +++ b/client/menu/scroll_container_custom.gd @@ -19,11 +19,15 @@ class_name ScrollContainerCustom # Adds support for scrolling with joypad and touch const SCROLL_SPEED := 1000. +var velocity := 0. func _process(delta): + velocity = G.interpolate(velocity, 0., delta * 5.) + velocity = 0 if abs(velocity) < .001 else velocity if Input.get_axis("scroll_up", "scroll_down") != 0.: - set_deferred("scroll_vertical", scroll_vertical + Input.get_axis("scroll_up", "scroll_down") * delta * SCROLL_SPEED) + velocity = Input.get_axis("scroll_up", "scroll_down") + set_deferred("scroll_vertical", scroll_vertical + velocity * delta * SCROLL_SPEED) func _input(event): if event is InputEventScreenDrag: - set_deferred("scroll_vertical", scroll_vertical - event.relative.y) + velocity = -(scroll_vertical - (scroll_vertical - event.relative.y)) * .1 -- cgit v1.2.3-70-g09d2