Help with movement tweening

0 favourites
  • 11 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I started to dig through the 164 pages of posts here, but I became discouraged around page 25 or 26 >.<

    I have a small issue that I'm uncertain with how I want to do this. I'm moving from an AS3 environment so I had functions like tweening to allow for smooth movement.

    C2 didn't have a movement system that worked the way I designed this game so I simply created it, but I really need a tweening.

    Right now I hard set the coords by saying on left -> player.x = player.x + 64. I was curious if there was a prebuilt functionality that would say player.x slide +64 to allow for a smooth transition while playing the animation.

    I've written out a quick and dirty method that should allow me to use globals and the every tick or every second abilities to properly move the player, but if C2 has an easier way already built in then I'd rather use it than wasting my event limiters on the free edition.

    I won't care about the "cleanliness" of my code quite so much after I can afford to pick up a standard license, but until that time I'm going to act like a C developer on a 386 :D

    Any help would be great and thanks in advance.

  • I'm not sure exactly what you are looking for, a little more specifics would be nice.

  • I'll see if I can clarify more.

    This game is a tile based game. When the player is standing on a tile they can move in cardinal directions. At this time my code simply sets the x or y coordinate to the next tile (64px difference). It "looks" awful to have the character just skip around. I have an animation made that would look great, but I need the character to move slowly across tiles.

    When the player hits right I want the player.x to increase by X amount until it reaches the 64px difference. So like... PLayer.X would have to increment x pixels over time until it reaches the final destination.

    Forgive me for using the Flash Game developer terms as I know they don't technically apply here, but this smooth movement is a tween.

  • There are several possibilities, lerp(a,b,t), custom movement behavior, or even rex's move to behavior.

  • EDIT: missed the train!

    I see, you want smooth grid-based movement.

    The 'move-to' custom plugin wold be ideal if you aren't interested in the Scirra arcade. Alternatively, you should look into the lerp() function. It can be a bit confusing at first but you will get nice smooth motion with deceleration.

    To do lerp:

    every tick:

    set object x to lerp(self.x,destination.x,speed*dt)

    set object y to lerp(self.y,destination.y,speed*dt)

    Speed should be some value for the speed of the movement.

  • sqiddster

    The use of lerp in that specific case can be a pain for many reasons:

    • it's not a linear movement, it's an ease out. For grid movement it might look a bit weird
    • it's very unprecise because the way you use it is the "tricky" way and you reach destination only because of floating point rounding. So you have to do sensibility checks if you want to stay on grid.
    • the speed value is not really a speed, it's only a factor that make the interpolation faster of slower but it's not a 'x pixel per second' value (ok I'm being picky here (: )

    so yeah for grid movement I prefer either using what I posted, or using lerp but by making the third parameter (t) evolve from 0 to 1.

    Using lerp could be intersting because this way you can do ease in or out like this

    set X to lerp(start,end,t^2) for ease in

    set X to lerp(start,end,t^0.5) for ease out

  • You could also vary the t element based on a percentage, like (int(timer)-timer)%10.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah, making the third term in lerp() the variable is probably a really good idea.

  • Thanks so much everyone! I'm going to toy around with lerp and see what I come up with.

    I had a feeling I'd be working with the Every Tick Event and lerp will simplify the math of the movement.

    Now if only I could spontaneously develop the art skills to make things attractive >.<

    Thanks again for the help!

  • To do lerp:

    every tick:

    set object x to lerp(self.x,destination.x,speed*dt)

    set object y to lerp(self.y,destination.y,speed*dt)

    Speed should be some value for the speed of the movement.

    You don't have idea how many time I spent searching for this! There's a lot of lerp threads around here but this is the 1st time I could make it work.

    Thanks bro!

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