Elasticity
Thursday, March 20th, 2008Both my games Zwingo and Squidgy use elasticity for the main control. Elasticity is the effect of making a MC follow the mouse while keeping it’s momentum if the mouse stops. Picture holding a yoyo on a string, looking straight down on it and moving the yoyo about. View the example here.

Create a circle on the stage and convert it to an MC, instance name ball. Add the following code to the main timeline:
The variables we set are xspeed, yspeed, fric (friction) and ease. Alter these later if you want.
Each frame we add the difference between where the ball is and where it needs to go divided by ease on to the speeds. We then multiply the speed by friction, in other words friction has an effect on the ball. Finally we relate this speed to the ball’s properties, and the effect is complete.
Say at first, xspeed = 0, the difference from the mouse to the ball is 100. This means the resultant speed is (0+100/10)*0.9=9
The next frame, xspeed = 9, difference = 91 so resultant speed is (9+91/10)*0.9=16.29
As you can see, as the ball gets closer (difference gets smaller), the speed increases. Now lets see what happens when the ball passes the target:
xspeed = 20, difference = 0, so resultant speed is (20+0/10)*0.9=18
Then xspeed = 18, difference = -18 (the ball has passed to the other side), resultant is (18-18/10)*0.9=14.58
Now that the ball has passed the target, it starts to slow down.

