Question about Interpolate
wpaten
Member, PRO Posts: 281
Hey guys,
I spent some time working in Corona and something that they have is different modules that allow me the ability to have playful interpolations with images. Things like Bounces and such. I wasn't sure if there was a mathematical way to incorporate these kinds of things into the Interpolate Behavior that we have now so we had more to choose from, other than just the standard 4?
Thanks,
wpaten
I spent some time working in Corona and something that they have is different modules that allow me the ability to have playful interpolations with images. Things like Bounces and such. I wasn't sure if there was a mathematical way to incorporate these kinds of things into the Interpolate Behavior that we have now so we had more to choose from, other than just the standard 4?
Thanks,
wpaten
Comments
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Ahhhhh. Nothing like sweet, sweet Gopple-Dee-Gook from a Mad Scientist Genius, to make a man feel quasi-neantherthal-ish. ;-)
Basically what I mean is if your actor is moving up and down (or left and right) via the magic of a sine wave . . . .
Constrain Y position to radius*sin(angle) (assume the angle is constantly changing)
. . . and the angle is limited so only the top half of the sine is used . . .
Constrain Y position to radius*sin((angle)%180)
. . . It will now 'bounce' rather than smoothly move up, down, up, down (etc), now reduce the radius over time . . .
Constrain Y position to ATTRIBUTE*sin((angle)%180)
Interpolate ATTRIBUTE from big to small
. . . so you have a bounce that is getting progressively smaller, like a ball bouncing on the floor loosing its kinetic energy . . . but the length of each bounce remains the same (the speed at which you are changing the angle the sin function is operating on), so you also need to increase the speed the angle is being swept through to compensate for the reducing size of the bounce, first let's use game.time to sweep through the angle . . . .
Constrain Y position to ATTRIBUTE*sin((game.time)%180)
Interpolate ATTRIBUTE from big to small
. . . now let's speed up game.time as the radius reduces . . .
Constrain Y position to ATTRIBUTE*sin((game.time*ATTRIBUTE2)%180)
Interpolate ATTRIBUTE from big to small
Interpolate ATTRIBUTE2 from small to big
. . . et voilà, you have a bounce that settles . . . actually it never really settles, so also throw in a rule to kill off the bounce below a certain threshold . . .
If ATTRIBUTE > a tiny size then do this:
Constrain Y position to ATTRIBUTE*sin((game.time*ATTRIBUTE2)%180)
Interpolate ATTRIBUTE from big to small
Interpolate ATTRIBUTE2 from small to big
Hope that makes a little more sense, when I'm at my computer later I'll stick it into GameSalad and so how it looks, it should look bouncy!
Ok I see what you did there. Very sweet.
Your example works if the actor is already moving? What if it is stationary? So for example, if you have a button on the screen that when clicked, will have a bouncy effect (getting smaller and then larger with the bouncy effect applied to it). The x & y would be replaced with w & h, however how would you apply the bounciness from a stationary standpoint?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok, that was straightforward enough . . . click to bounce:
(of course all the values can be changed to suit)
Link: https://www.mediafire.com/?kn0onns9t9rpooq
Ok, now to try a button . . . . back in a second . . .
Here you go, same basic deal, but applied to height and width . . . .
(again, there's a ton of scope to adjust all the settings to taste)
Link: https://www.mediafire.com/?fxy8x2cqnls8hg7
That's 14 Exclamation Marks worth of Fantastic. :-)
You should add this file to that thread with all the useful code as well.
It should look something like this . . .
(20-( self.Time *20))*sin((( self.Time *(400+( self.Time)*400))-90)%180)+50
(20-( self.Time *20))*sin((( self.Time *(400+( self.Time *400)))-90)%180)+50
Hold on, I'll try it out . . . . back soon . . . .
Link: https://www.mediafire.com/?6p7w4hx2mb94dzh
Beautiful!! The beauty of this is that with a few minus signs put in, you also have the ability to have them shrink on touch instead of grow on touch.
Thanks a bunch man. Much appreciated.
If you want it to shrink on touch, play around with these values . .
(30-( self.Time *(30))*sin((( self.Time * (400+( self.Time *600)))-90)%180)+50
The basic 'core' size.
How much the size grows and shrinks by.
The basic equation looks like this:
Constrain Attribute:[ self.velocity ] To:[ ( self.velocity + ( self.targetWidth - self.Size.Width )* self.k )* self.damp ]
Constrain Attribute:[ self.Size.Width ] To:[ self.Size.Width + self.velocity ]
Basically its creating a velocity that is used to readjust the width. But the velocity is too fast and overshoots the target width. Then it goes in the opposite direction but overshoots again. (And so on.)
It would oscillate forever, but we add a dampening effect that slightly slows the velocity down (kinda like friction). That's the attribute: self.damp.
There is also an attribute called: self.k. (That's what Hooke called it. And it stuck, I guess.) Its a measure of how springy the object is.
You can mess with different values of self.damp and self.k. It will give your button different properties.
Here is a demo:
http://www.mediafire.com/download/zwlvniqtseuala9/SpringyButton_HookesLaw.zip
Great stuff !! >-
myReallyFancyButton
Hey thanks man!!! Very nice.
@wpaten -- you are welcome! By the way, all my friends and family really love the children's apps you produce. They are just right!