Single Transition across multiple Tweens

Godot Version

4.2.1

Question

Hi there. I’m working on a grid based game, and I would like to have a single tween transition for multiple position interpolations Here’s how my movement is working right now :

var queue_movement = []

func move():
  for newPos in queue_movement:
    var tween = create_tween()
    tween.tween_property(self, "global_position", newPos, 0.2)
    await tween.finished

The problem with this code is that the movement feels wrong, and I would like to use some transitions (as in tween.set_trans() ).
But, if I do that, the transition will play on each newPos, and not on all of them

for exemple, for 3 positions, here’s what’s it’s doing :

  1. In → out
  2. In → out
  3. In → out

What I would like :

  1. In → linear
  2. linear
  3. linear → out

have you tried doing the animation on animation player?
it sounds like what animation player can do, but really tween also can do that by making it into 5 or 3 tween_property.
if 3 tween property():

  1. ease in, trans sine
  2. ease out-in, trans sine
  3. ease in, trans sine

something like that

I have not tried animation player because I don’t know the positions before hand, so tween seemed to me like the correct option

As for your answer, the entities moving on the grid have multiple ways of moving, and that could be for 1,2,3 or X tiles, so I need something that could work in most cases

this just make different tweens/animation walks i think

i see what you meant now, you can actually put function into an array, by using its callable
then just .pick_random() from the array for each movement, and .call() it to execute the function chosen
each different functions has different ease and trans

it will be complicated on how you gonna wait for each tween to be finished, i havent tested await from callable function. for now you can wait exactly 0.2 seconds for each function called by its callable

Thanks for the help, kleonc on discord found a different approach to my problem that seems to work perfectly :

i see, so using lerp instead, completely forgot it existed.
try it yeah

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.