How do I follow smoothly?

0 favourites
  • 6 posts
  • Thought I had a system to make characters follow like a classic RPG:

    ...but as you can see the second character isn't moving smoothly as there is some jumping back and forth.

    All I did was while the player is moving to add his position at the back end of an array and set the position of the follower to the one at the front end of the array (and remove it).

    Since this is done every tick I thought that may be the issue, since ticks aren't consistent. So try doing every X seconds, which made it a little smoother but not completely smooth.

    Any ideas or suggestions?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • did you try the pathfind behavior? maybe it will work smoothly, but maybe will have some delay.

    or you can try to adapt something from this tutorial: https://www.scirra.com/tutorials/626/ma ... ing-camera

    (use the lerp on what you have done with the array)

  • did you try the pathfind behavior? maybe it will work smoothly, but maybe will have some delay.

    or you can try to adapt something from this tutorial: https://www.scirra.com/tutorials/626/ma ... ing-camera

    (use the lerp on what you have done with the array)

    I was thinking more along the lines of ideas to smooth this system out. Pathfinding isn't great for short distances like this and I have new coordinates every tick so lerp wouldn't into this system. I could create a system that just records the changes in direction and lerps the distance in between, would just have to make sure to get speed/timing correct.

    I've also tried using 8 direction controls which worked easily except that if the follower gets stuck on a solid it can be thrown off permanently.

    Before moving onto a different system though I wanted to figure out why this isn't working, as to learn from it and see if solvable (before moving on to something completely different). I am thinking it is due to a variable framerate. Does that mean adding delta time in somewhere is the fix?

  • Can you isolate and recreate the issue to share?

    Also have you checked the origin points of your animation frames to make sure they are lined up?

    Edit: It probably does have to do with frame rate. While the leader looks smooth, the distance traveled probably differs per frame, so some frames the recorded distance is slightly farther, and some slightly shorter. The stuttering becomes apparent when you have a reference point such as the follower to the leader (or the viewport, which is following the leader) - If the leader on a given frame is slightly ahead, while the follower on that frame is slightly behind, you'll see a gap widen, and then it pops back as it corrects or overcorrects in the following frame. You can test this by having the viewport follow the follower and see if it starts looking like the leader is stuttering instead.

    As for a solution, I would suggest using the move towards action instead, but that has its own complications like cutting corners and stuttering when catching up as well..

    Edit 2: Also for pixel art, do you have pixel rounding enabled? That is probably the bigger culprit. Try disabling it and see what happens.

  • Can you isolate and recreate the issue to share?

    Also have you checked the origin points of your animation frames to make sure they are lined up?

    Edit: It probably does have to do with frame rate. While the leader looks smooth, the distance traveled probably differs per frame, so some frames the recorded distance is slightly farther, and some slightly shorter. The stuttering becomes apparent when you have a reference point such as the follower to the leader (or the viewport, which is following the leader) - If the leader on a given frame is slightly ahead, while the follower on that frame is slightly behind, you'll see a gap widen, and then it pops back as it corrects or overcorrects in the following frame. You can test this by having the viewport follow the follower and see if it starts looking like the leader is stuttering instead.

    As for a solution, I would suggest using the move towards action instead, but that has its own complications like cutting corners and stuttering when catching up as well..

    Edit 2: Also for pixel art, do you have pixel rounding enabled? That is probably the bigger culprit. Try disabling it and see what happens.

    Oosyrag, great analysis, as usual.

    Pixel Rounding is off.

    Following character moves smoothly on his own.

    When switching the view-port to follow the follower the leader does stutter.

    I could recreate but think it might be solved thinking about it logically:

    I agree the main issue is likely the varied framerate. I tried to change it to per second but doesn't seem to work probably due to the fact if the interval is too small it will still only run once per frame. And of course if too large it won't be smooth.

    So if the timing is based on a variable framerate the important part is to keep the follower the same distance from the leader the whole time.

    This seems to work pretty well so far.

    What I did was every tick add a L/R/U/D to a variable on the follower. Then set the position to the player, instead of the NPC as in previous tries, based on the count of each. Then remove the one at the beginning. That's the basics of it at least.

    Thanks again Oosyrag for the insights!

  • Looks great!

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