Sunday, June 17, 2007

Fathers Day

Father's Day was today, and I had my father's day animation to show my dad. If you haven't seen this animation, you should probably visit Blazing Games and take a look. The animation was done entirely in ActionScript 3. Even thought the animation appears fairly complex, it was in fact not that difficult to create. While I am not going to open up the source code yet, I will explain how it works. Each fish controls it's own movement with a movement function that is called every frame. While a time based interval would be more accurate, for this animation I really didn't need accurate timing for the movement, but for an action game this can be an issue.

The fish movement logic is very simple. It consists of a delay before starting to move, and a target location that the fish is going to swim too. When the movement function is called, the delay countdown is checked, and if the delay is over, the fish is moved by a set amount along the x axis (horizontal position). The y axis (vertical position) is where things are interesting. The vertical movement is in a sine wave along the horizontal line that crosses through the particular target y coordinate. The amplitude of the wave is based on the distance from the target, so as the fish gets closer to the target, the smaller the vertical movement will be.

Once all the fish have reached their target location, they are given a new target with a short delay. As the delays are the same for all the fish, they will swim off in formation. Once they have all reached their off screen location, they are moved back to their beginning off screen location. You may be wondering how the fish initially swim out in random order if they are in proper formation. Quite simple. They are given a random delay amount so their start times will all be different.

No comments: