Tween Move at speed rather than for a duration

Hi there,

I’ve added a Tween to my Sprite, I want the Sprite to go to a certain Y position when a button is pressed. Rather than the time it takes for the Sprite to get there being determined by a duration set, I’d like it to move a certain speed. So if the Sprite is further away from the defined Y position it will take longer than if the Sprite was already close to the defined Y position.

Thank you

Hi!

It is possible to tween the object position with constant speed, here’s how:

Here you need the variable, which defines the speed (pixels per second), and when you divide the distance with the speed, you’ll get the time, what the object should use for the travel.

In the example above the box1 moving 300 pixels will travel 300/500 = 0.6 seconds, whereas the box2 moving 500 pixels will travel 1 second.

You can also use forces to do the movement (where you can define the speed in pixels per second), but with tween you can use different easing methods.

Hope this helps. :slight_smile:

1 Like

You legend, thank you.

As stated. It’s distance divided by speed.

1 Like