SpyrexDE / SmoothScroll

Addon for the Godot Game Engine that adds a SmoothScrollContainer.
https://spyrexde.github.io/SmoothScroll/
MIT License
132 stars 10 forks source link

Refactor handle_content_dragging #32

Closed HaroldLever closed 9 months ago

HaroldLever commented 9 months ago

To fix #27 .

SpyrexDE commented 9 months ago

It looks like you removed damping for dragging completely, however, damping when overdragging was wanted behaviour. The problem described in #27 is only occuring when the mouse is moved fast enough.

Edit: Nevermind, you actually have added overdragging, however with the same values it behaves very differently to the previous implementation.

SpyrexDE commented 9 months ago

I think your implementation is really good, but the documentation could be better. I still dont fully understand what you did 😅

HaroldLever commented 9 months ago

@SpyrexDE Sorry for forgetting to explain that the damping behavior might be slightly different than before, I changed the factor in the latest commit. Is it the effect you want? Drag back slowly

SpyrexDE commented 9 months ago

Yeah, the result is great and will infact fix #27. Im just unsure about what the variable "a" is and how pow(delta + pow(a, 1/(1-a)), a) - pow(pow(a, 1/1-a), a) works. Could you maybe try to explain a bit how your solution in general works? I would greatly appreciate that :)

HaroldLever commented 9 months ago

Well, instead of applying velocity, I chose to set position directly, but I set velocity to let it scroll once dragging ends. y_pos = calculate_position.call() velocity.y = y_pos - pos.y pos.y = y_pos

Therefore, velocity should not be added to position when dragging. if not content_dragging: axis_pos += axis_velocity

I chose mouse/touch relative movement to calculate where the content's position should be. Assuming y is position and x is event's relative movement. Formula

The derivatives when x equals 0 should be 1 to make it a continuous function. Although I think it might be too complex. The rest part is to modify the factor to make it looks good. var a = (1 - damping * 0.5 - 0.1)

SpyrexDE commented 9 months ago

That helped a lot, thank you so much!