Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | newgame |
For example, 2D animations all stop when velocity is 0 via the usual code
get_node(...).stop()
Animations often stop at some middle-of-the-animation frame because velocity is 0. How to add a history of velocity check to it? Animation stops if current velocity is 0 and past velocity for some time was 0.
Even better in general, finer granularity, using nested history of velocity checks, in pseudo-code:
if velocity is > X pixels/s & velocity was > Y pixels/s sometime in the last 10 seconds & average velocity was > Z pixels/s for last 20 seconds
get_node("...").animation = "..."
(and a long list of these)
What is the correct GDScript syntax needed for that? What is the best GDScript manner to write that?
-
“&” should be achieved via nested “if … else …” but is there a more direct way to write it? Presumably more efficient?
-
Are there already functions in GDScript for averaging or reading the maximum of some variable reached during some time period? What about the minimum reached during some time period?
Your second question asks, “Are there already functions in GDScript for averaging or reading the maximum of some variable reached during some time period?” If you need to keep a variable in some range, you can clamp the variable. For example:
some_value = clamp(current_value, 0, 10)
Hope that helps.
Ertain | 2022-09-30 17:33