[SOLVED]Tween - Stop if position is reached

The problem im facing is,
whenever I tween object1 position towards object2 while object2 is moving, I can’t use the “trigger once” condition, otherwise object1 won’t tween to object2’s actual position (but to the position where object2 was when the tween started).
Therefore the tween has to be repeated every Frame.

An option “stop tween if point is reached (or tween is finished)” could improve performance. There already is an option “destroy this object when tween is finished”.

OR somehow make the object tween until it reached the position while “trigger once” condition is used. Because repeating a tween every frame changes its ease; “linear” will look like “easeOutQuint”.

Keep additional variable to track the position of object2. Updates these whenever object2 position changes. Then use these variable as target position for tweening object2. This way you ensure that the object 1 is tweens toward the correct target position if the object2 is moving.

Hi, there are many workarounds. But none seems to be quite practical.

There is an action to stop a tween:

image

1 Like

Hi, yes but this is not what I’ve meant :smiley:
This way you still have to check every frame if the object reached its point, creating additional events which on many tween objects can be difficult to manage or tweak.

Do you want to stop the tween or automatically remove the tween when it’s done playing?

Instead of a trigger once, you can use tween exists or tween is playing

instead of of depend upon trigger once conditions use a Boolean variable as a flag to indicate weather the tween should continue or not. Set this variable to true when you start a tween and set it to false when tween reached to its destination.

Just a heads up, the original intention behind this goal is already outside of what tweens are designed to do. This is true in other engines like Godot, Unity, and even things like Roblox.

Tweens are meant to apply an easing (mathematical calculation) with an exact curve from a start value to an end value. That exact curve cannot exist if the end value keeps changing. This is not specific to GDevelop, and is true of how tweens work.

Any tween that tries to use a moving target will no longer have the accurate easing calculation, and will appear slower (or faster) than it should, and can lead to something like ease in/out looking more like linear, or another tween entirely.

Now, all of that said, is it possible to do?

Yes, but you’ll need to do quite a bit of stuff: update the tween each frame with updated the start/stop destinations AND you’ll need to update the duration to account for the remaining time (compared to the prior frame) so that the easing still applies as expected.

It will involve a lot of math with TimeDelta() expressions, and variables to track what you’re wanting, but it is potentially doable (also note that tweens are resource intensive so restarting a tween every frame will impact your performance).

That said, if you don’t care about the easing being correct compared to a stationary destination, all you need is an event with the “Tween is playing” condition and a “YourTweeningOBjecthere position is YourdestinationpositionX” (and/or Y position/rotation/etc) condition, along with the “Stop tween” action, which already exists:
image

1 Like