Help with movement tweening

Get help using Construct 2

Post » Fri May 11, 2012 2:40 pm

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.
B
20
S
2
G
3
Posts: 7
Reputation: 3,311

Post » Fri May 11, 2012 2:44 pm

I'm not sure exactly what you are looking for, a little more specifics would be nice.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri May 11, 2012 2:49 pm

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.
B
20
S
2
G
3
Posts: 7
Reputation: 3,311

Post » Fri May 11, 2012 3:36 pm

There are several possibilities, lerp(a,b,t), custom movement behavior, or even rex's move to behavior.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Fri May 11, 2012 3:38 pm

Last edited by Yann on Sun Sep 14, 2014 8:32 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri May 11, 2012 4:43 pm

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.sqiddster2012-05-11 16:44:10
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri May 11, 2012 6:07 pm

@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 outYann2012-05-11 18:08:15
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri May 11, 2012 6:30 pm

You could also vary the t element based on a percentage, like (int(timer)-timer)%10.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Fri May 11, 2012 6:33 pm

Yeah, making the third term in lerp() the variable is probably a really good idea.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri May 11, 2012 7:42 pm

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!
B
20
S
2
G
3
Posts: 7
Reputation: 3,311

Next

Return to How do I....?

Who is online

Users browsing this forum: jobel, Timedoor Indones and 23 guests