Flash Components      Flash Menu      Flash Gallery      Flash Slideshow      FLV Player      Flash Form      MP3 Player      PhotoFlow      Flash CMS      3D Wall      Flash Scroller

Flash / AS

Silverlight

WPF

ASP.net / PHP

Photoshop

Forums

Blog

About

 


FlashComponents
  Galleries
  Slideshows
  Menus
  Design & Effects
  Audio & Video
  User Interface
  Templates

 

 

 

 


Predicting Collisions - Page 6
       by kirupa  |  23 October 2005

In the previous page, I finished explaining what all of the ActionScript code does. In this page, I will summarize what was discussed in the past five pages.

Quick Summary
Occasionally, for longer tutorials, I will try to provide a quick English-only summary of the code in a few paragraphs. That may help to give you a better idea of how the code spread across the previous pages fits together.

When you click your mouse at a target, your mainCircle movie clips begins to move in that direction. The code for the movement is based on Lostinbeta's tutorial. Here is your objective: you want any objects that lie in the mainCircle's path to move out of the way. You need to predict a collision before it happens.

You check for collisions by sending out a number of path circles that propagate towards your final target. The number of circles you send out is determined by your steps variable. Any object that collides with any of the path circles is instantly added to an array (final_targets). In the end, the final_targets array contains the name of every obstacle that is in the mainCircle's path.

Once you have a list of names in your final_targets array, you realize that they must be moved or else face collision with mainCircle. Using the moveAway function, you cycle through each name found in the final_targets array and move those named objects out of the way.

All of the above happens before your mainCircle has even moved a few pixels!

External Tutorials Referenced

This tutorial relied heavily on code and ideas from the following tutorials:

  Easing on Mouse Click (by lostinbeta)

  Collision Detection Among Multiple Objects

  Finding Values in an Array
 

I hope the information helped. If you have any questions or comments, please don't hesitate to post them on the kirupa.com Forums. Just post your question and I, or our friendly forum helpers, will help answer it.

The following is a list of related tutorial and help resources that you may find useful:

How to use the Forums
New, Upcoming, and In-Progress Tutorials
How to Help out kirupa.com
Writing Tutorials
 
Cheers!
Kirupa Chinnathambi
kirupaBlog

 


page 6 of 6


 


kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components
flash menus, buttons and components Digicrafts Components
The best flash components ever! Entheos Flash Website Templates
Buy and sell FLAs at Ultrashock! Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Purchase & Download Flash Components flash components
Learn how to advertise on kirupa.com