How do I make a sprite go to a position over time?

  • Probably one of the biggest beginner questions in existence, but I honestly can't find anything about this!

    All I want to do is have a sprite go to a location (at a consistent speed throughout) in a specific time, and stop once it's there. That's really it!

    Here's an image of what I want to do if it's needed. You can ignore the text.

    I really don't know how else to explain this further because it's such a simple thing that I can't seem to work out. If anyone could just let me know the proper way to go about this, I'd really appreciate it.

    As a quick sidenote, I do not mean having a sprite that always goes the same speed to a location - because then if the distance is a lot smaller in one occasion compared to usual, it'll finish it much faster than a longer distance. What I'm wanting is for the time this movement happens in to always be the same. So the one moving a smaller distance will move slower to ensure it takes the same amount of time.

  • Haha I know, it is something quite simple and we need to use it all the time, but it is complex. The easiest option that I always use, is using rexrainbow's moveto plugin:

    If you want it to have an ease in and out speed effect, you will need to use lerp:

  • you can do this easily with bullet behaviour, there is a moveto example in the new project dialog..

    Just set the speed based on the distance..

  • Haha I know, it is something quite simple and we need to use it all the time, but it is complex. The easiest option that I always use, is using rexrainbow's moveto plugin

    Thanks! That plugin is exactly the type of thing I was looking for.

    Just as one last question, how would I set the speed to be correct depending on the position the sprite is going to be moving to?

    What I mean is that if I wanted a sprite to get to a position within 1 second exactly, the speed would change accordingly to ensure it takes exactly that long, no matter what the distance is. It'd move quicker if the distance was large and slower if the distance was small because of this. Do you know a 'proper' way to calculate this? My horrible workarounds have always been these extreme mess of events that never really work out that well. (You can probably tell I'm a real newbie with this!)

    Edit: Never mind this, I'm going with the LiteTween plugin. (Check the post below.)

  • LIteTween is another option, and is time based.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • LIteTween is another option, and is time based.

    Ah, this one is perfect. All I need to use here is the linear option and change the duration / position for each location, and it works flawlessly. Many thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)