Flint Line Collision Tutorial

I have made this tutorial to help make it clearer how to do line collisions using my Bounding Shape action in Flint. This tutorial is not necessarily the best or most efficient way of doing this, it is just the way I have found to work well for me.

You are missing Flash content that goes here

Flint Line Collisions Example

First you will need to download and extract the Flintcollide.rar file that I have put together, contained within this archive is the Flint code from the Lines and Collisions Branch of the SVN with the addition of my own BoundingShape.as file in the twoD/actions folder. Within the flint source code I have removed the flintparticles/threeD folder to reduce file size since this technique is 2D only. Also within this archive I have included the flash file of the line collisions example shown above.

Flintcollide.rar | Updated Flint code, with example Flash file.

Now with the above file extracted, open the Flash/collide.fla file in flash. If you have not changed the file structure of the downloaded archive you should be able to publish (F12) the file without errors and see the example swf above.

To get line collisions to work in your own projects you will first need to make sure that the flint collide library source code you previously download is in the classpath for the project, this webpage documents how to do this. If you have been using the SWC version of the Flint code previously you will need to unlink this from the project.

Now within your action script code you will need the following two lines, the first line creates a new LineZone, this is the line you want the particles to bounce off. The second line creates a new BoundingShape instance and adds the action to the emitter. You will also need the respective import declarations.

var collideLine:LineZone = new LineZone( new Point(150, 400), new Point(300, 250) );
    
emitter.addAction( new BoundingShape( collideLine, 1 ) );

The BoundingShape class accepts two variables when creating it, the first is the LineZone you want the particles to collide with and the second is the Bounce coefficient of restitution when the particles bounce off the line, this should be a number from 0 to 1, this is that same as with the BoundingBox class (See documentation here).
These lines of code can be simplified to this:

emitter.addAction( new BoundingShape( new LineZone( new Point(150, 400), new Point(300, 250) ), 1 ) );

This code is not perfect and has problems in the same way the collide particle action does as it is designed for speed over accuracy. It should also be noted that I did not create the code which calculates the collisions this was created by Richard Lord the author of flint and was in the SVN, I simply created a 2D action that implemented this code.

When the particles are travelling at a high speed it becomes more likely for the particles to travel through the line and not collide, to reduce the likeness I suggest you try to keep your frame rate as high as possible as the longer between calculations the more likely it is the particle will jump over the line. Also increasing the collision radius helps stop particles going through, but it should be noted that with a high collision radius some particles instead of jumping over the line get stuck on it and bounce inside it till they reach the end.

emitter.addInitializer( new CollisionRadiusInit( 5 ) );

All credit should go to Richard Lord at Flint for creating this amazing action script library. If you have any problems leave a comment.

Article Author

Pieter Vanderwerff

I am a visualisation expert based in Wellington, New Zealand. I enjoy creating new and interesting solutions that combine my experience in different design fields to create unique outcomes.

4 Comments

Hey,
Just noticed something with the example on this page; if I load my GPU quite heavily, it seems it stops detecting most of the collisions causing the particles to just fly through the lines. Don’t know if it’s at all important, but I thought I should mention it.

10:43 AM
06 May 2009

Jake

With flash the GPU should not matter, only the new flash player 10 has the ability to interact with the GPU and this example certainly does not take advantage of this. My guess is the GPU is straining the CPU resulting in a lower frame rate in the swf, increasing the time between calculations and allowing the particles to ‘jump’ over the line. If performance is important to you there is a counter that releases particles based on the frame rate so at times when the CPU is loaded the particle count would decrease but the calculations will become more accurate.

See performance adjusted counter documentation here.

10:42 PM
06 May 2009

Pieter Vanderwerff

Hey again,

Thanks for the tutorial, it is extremely helpful! I had one question though: Does the BoundingShape class take any other shapes besides a LineZone, like a DiscZone?

5:59 PM
09 May 2009

Harrison

Harrison, after your comment i had a look in the Flint SVN to see about other Zones, and yes Richard has updated the lines and collisions branch to include support for different zones. But unfortunitly my bounding shape code as it is will not support these other zones. I have the new code now and will have a go updating it now.

Check back soon for updates on this

12:57 AM
10 May 2009

Pieter Vanderwerff

Write a Comment

Name and Email are required. Basic html is supported in comments.

Name

Email

Website

Comment