Search tutorials
One of the most requested tutorials is on collision detection and how to use it. Collision detection is used to check to see if two or more objects have come in contact with one another. In this tutorial I'll show you how it works. I have made this tutorial as simple as possible for you so that you can immediately apply it to your own projects.
To begin with, here is the code for you to look at.
Set Variable: "red_x" = GetProperty ("/red",_x)
Set Variable: "red_y" = GetProperty ("/red",_y)
Set Variable: "green_x" = GetProperty ("/green",_x)
Set Variable: "green_y" = GetProperty ("/green",_y)
Set Variable: "red_h" = GetProperty ("/red",_height)/2
Set Variable: "green_h" = GetProperty ("/green",_height)/2
Set Variable: "red_w" = GetProperty ("/red",_width)/2
Set Variable: "green_w" = GetProperty ("/green",_width)/2
Set Variable: "distance_x" = red_x-green_x
Set Variable: "distance_y" = red_y-green_y
Set Variable: "area" = (red_h+red_w)*(green_h+green_w)
If (distance_x*distance_x+distance_y*distance_y<=area)
Set Variable: "/:status" = "Collision Detected"
Else
Set Variable: "/:status" = "No Collision Detected"
End If
Let do this, step by step...
- Start up a new movie in Flash 4.
- Make the size 500 x 400.
- Now make two squares and colour one RED, and other GREEN.
- Next make a blank movie clip - To do this click on Insert > New symbol, choose Movie clip as its behavior, and name it processor. The reason it's named processor is because it will contain the actionscript mentioned earlier that will check for a collision.
| » Level Basic |
|
Added: 2000-07-13 Rating: 7 Votes: 68 |
| » Author |
| -- |
| » Download |
| Download the files used in this tutorial. |
| Download (51 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!