Godot Version
v4.5.stable.official [876b29033]
Question
I have a card (Node2D) and when I drag it fast in the y-direction, I want to decrease its y-scale to give the impression of the card tilting in the 3rd dimension.
However, if I base the y-scaling only off of the current y-velocity, the animation is way too sharp & sudden and doesn’t look good.
In plain and simple terms, I’m trying to achieve something similar to Hearthstone’s card tilting animation when dragging around a card from the hand.
Looking to optimize for performance.
I am contemplating a few approaches:
-
Store velocity hist in GDScript Array
- Store velocities in a GDScript Array and then
.pop_front()any velocity older thanXseconds.
Disadvantage
.pop-front()shifts each index on every execution, so it is O(n) time.
- Store velocities in a GDScript Array and then
-
Velocity hist tracking via C# queue
- Same concept as above, but leverage C# queues. I think O(1) time?
Disadvantage
- Is it possible to mix C# and GDScript? Is it expensive?
-
Execute y-scaling at a fixed
scaling units / secspeed and only trigger new y-scaling if not busy- Calculate desired duration based on scaling speed and pass it to a Tween, then only execute a new Tween if current Tween not busy. O(1) time. O(1) time.
Disadvantage
- Is it possible to track whether property Y of object X is currently being Tweened?
Am I overthinking this? Is there something built-in to solve such a problem that I’m not aware of?