How do I make reverse bounce using sin expression?

0 favourites
  • 9 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I have an object that I want to bounce using the sin expression, as it will be linked to an animation. I kind of found a solution but it's not exactly what I'm after.

    I'm using an instance variable called progression. each tick I'm adding to this value until it reaches 180. Once it reaches 180 I then use a trigger once to set the value back to 0. This kind of worked to get the bounce, but my goal is to have the value decrease instead when i get to 180 to make it reverse again when I get to 180, and forward again when it get's to 0.

    I need to do this as a division of this value (progression/180*5) will also be driving which animation frame to show.

    I can't really wrap my head around how to make it reverse. I'm guessing I would need another variable to detect which end of the scale it last hit?

    Any ideas?

  • Bouncing is a very specific movement. Why not use the build in 'bouncers' ?

    https://drive.google.com/open?id=0B1SSu ... Th4aVdidGM

  • tunepunk

    in addition to the "Progression" instance variable. have an "Addition" instance variable.

    so, I guess Progression would start at zero, and Addition at 1 (or however much you were adding each tick.

    If Progression >= 180 then multiply Addition by -1

    if Progression <= 0 then multiply Addition by -1 again.

    Every tick set Progression to Progression + Addition.

    If you need to speed up the bounce, just make Addition a bigger number...

    ok, after thinking about this for another minute, I was thinking that the bounce animation might look un-natural playing backward - The object would appear to start to be squished before it hits the ground. You may want to have two animations - one for the way down, and one for the way up. So, when you are calculating what frame of the animation to show (based on Progression), could would also know which animation to use based on testing if Addition is positive or negative.

  • AllanR the bounce animation is not really a squash stretch animation, so I'm not really worried about it looking weird. I will try that out and see how it goes. I think it could work.

    It will be more of like, when the addition is positive the left foot will be in front, when the addition is negative the other foot will be in front.

    I'm using the sin to set the bounce height.

    I have a snappy 4 frame run animation very similiar to the one in the link, except that the character is not moving in Y axis. The sin controls the Y movement (bounce of the step)

    progression is between 0 and 20) set Frame 0 (feet together - step)

    progression is between 20-160 & addition is +1 - set Frame 1 (left foot in front - in air)

    progression is between 160-180 - set Frame 2 (feet together - step)

    progression is between 160-20 & addition is -1 - set Frame 3 (right foot in front - in air)

    Kind of something like that. I'm aiming to achieve a nice snappy & bouncy run animation using only 4 frames, where the sin controls the Y movement (the bounce of the step), having a smooth up and down bounce but a snappy four frame walk animation.

    The reason I'm doing it this way is that otherwize i would need a at least a 15 frame animation in every axis (8 direction isometric), to get a smooth up and down movement. That would add up to a lot of frames, for each character.

    I think your solution could work. I will try it out when i get back home.

  • tunepunk

    ok, now I see what you are trying to do.

    But, to do a normal run cycle you can't do the entire cycle in one bounce - it takes two bounces to get back to the starting point of the cycle (the legs pass each other only once per bounce).

    If you watch the video in your link in Chrome, you can set the speed to 0.25 to slow it down - you will see that the legs are fully extended at the top of the bounce. They only cross at the bottom when one foot is on the ground. It alternates between the left and right foot on each bounce.

    So, you will need another variable (maybe called "Foot") that alternates at the end of each bounce (every time the progression gets down to zero).

    You can still probably do it with 4 frames - but it will have to be spread over two bounces.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • AllanR it should be enough. 0 is on the ground 180 is on the ground, so everything in between is "in air". while progression is moving up to 180, left leg will be in front. (frame1), and while progression is moving down to 0 again after contact with the floor again at 180 the other foot will be in front (frame 3), so you solved it in one go i believe. There's the 2 bounces.

    progression =0 left foot touching ground(frame 0)

    progression 180, right foot touching ground (frame 2)

  • Bouncing is a very specific movement. Why not use the build in 'bouncers' ?

    https://drive.google.com/open?id=0B1SSu ... Th4aVdidGM

    Thanks. Just Checked out your example and it's a good solution, but unfortunatly i'm doing an isometric game so can't use the platform behaviour in this case.

  • You could use an equation like this to get the value to go from 0 to 180 and back to 0 based on time.

    value = abs((time*speed+180)%360-180)

    If you set speed to 180 it will take a second to go to 180 and another second to go back to 0.

  • R0J0hound Brilliant, just brilliant. Those kind of solutions I love. You never stop to amaze, thanks!!

    I wish math was one of my skills. I'm going to try out your solution as well.

    AllanR I got it working in this way using the sine behaviour instead. (similar thing)

    capx: if anyone finds it useful.

    https://dl.dropboxusercontent.com/u/20560446/Scirra/snappyrun.capx

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