Flint Collide Update

Richard Lord at Flint has updated the lines and collisions branch of the Flint SVN. It now supports collisions with some new Zone types and I guess in the future it will ideally support all Zones. As my BoundingShape class was written it does not support any Zones other than the LineZone, to accommodate for the new Zone types and for others to be supported in the future I have updated the BoundingShape class. The archive below has the updated Flint code as well as the updated BoundingShape class.

Flint_collide.rar | Updated Flint code, with updated BoundingShape class.

The way in which you use this class is just the same as outlined here, Flint line collision tutorial, the only difference is you will need the archived file above and the BoundingShape class now supports more Zone types.

So far there are only three supported Zones types, they are listed below with the AS3 code to implement them.

LineZone - See Documentation

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

PointZone - See Documentation

emitter.addAction( new BoundingShape( new PointZone( new Point(150, 150) ), 1 ) );

DiscZone - See Documentation

emitter.addAction( new BoundingShape( new DiscZone( new Point(150, 150), 50 ), 1 ) );

When testing the new DiscZone collisions I could not get them to collide accurately if at all. As I have said before I did not write the code for calculating the collisions I have just made the BoundingShape class to implement it. So try the new Zones for yourself and don’t forget to leave a comment back here telling us how you got on. Also check out the Flint SVN from time to time for updates of the linesandcollisions branch by Richard as all new updates should support this BoundingShape class.

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.

10 Comments

Hey,
Thanks for the update. I just spent some time with it and I think I found the problem with the DiscZone. For some reason it isn’t drawing the whole DiscZone, but just the center point. So if the particles are aimed at the center of the Disc, they will collide with just that point. My guess is that the source code from the SVN still needs some tweaking.

For now, you can get pretty close to a disc shape zone by using a bunch of small lines. It’s tedious and takes some trial and error, but it works out ok enough.

11:47 AM
12 May 2009

Harrison

Yes i found the same problem with the DiscZone, im not sure what the problem is but if you change the size of the inner radius then it will not even collide with that, if you want to have a go at fixing the calculation you can find it in the DiscZone.as file under twoD/zones.

As for making a circle with lines you might be able to make it more easily using a FOR loop and a simple equation, but remember the more lines you have the more calculations that will be required.

6:36 AM
13 May 2009

Pieter Vanderwerff

I believe I found the problem. If you get rid of the code:

if ( distanceSq > particle.collisionRadius*particle.collisionRadius ) { return false; }

I honestly didn’t really understand what that statement was for, which is why I tried commenting it out. The particles will bounce off the circle perfectly, but only when they hit the outside. Particles shot from within still pass through like there’s nothing there.

11:06 AM
13 May 2009

Harrison

Excellent i will have to try this, hopefully i can post the resulting test soon.

My guess for why the code is there is probably to test for how close the particle is to the zone and to quickly return it as non colliding if it is well away from the zone to increase calculation time. but yeah as you said it doesn’t work and returns false for most particles.

Have you tried changing the interior radius of the DiscZone? this could be what the calculation looks for to collide with and if you don’t set it, it will default to 0 so for particles starting inside the DiscZone they would never collide.

8:33 AM
14 May 2009

Pieter Vanderwerff

It actually completely dies if the InnerRadius is anything other than 0. Particles on the outside won’t even bounce off the outside.

I’m 99% sure that the problem is with how much more complex the DiscZone is than a LineZone. The code for the DiscZone collision is good for describing a particle on the outside moving towards the outside, but returns false for other conditions.

I think that with a series of if statements I can make it work: one for starting outside the OuterRadius, one for starting inside the outerRadius but outside the InnerRadius, and one for starting inside the InnerRadius. The second one will be the most complex, because it will have to deal with it hitting both the OuterRadius and the InnerRadius.

I might be able to get something patched together by tonight (I’m in EST, so it’s 9:30 am right now), but hopefully earlier. I’ll post the code if it works.

11:26 AM
14 May 2009

Harrison

Scratch that, it doesn’t appear that the math formula used to calculate the bounce can be reused like that. It really is written to bounce off the outside, not the inside. Which is funny, because the bounding shape idea is to keep stuff inside the shape.

My other idea is to have it create the formula for each circle and check if the particle’s point satisfies the equation. However, I have a feeling it won’t work so well, due to rounding errors, as well as it not being able to calculate all the square roots fast enough.

2:18 PM
14 May 2009

Harrison

Thanks for the update, I haven’t had time to look at it myself but hopefully I can have a look in a few days and post something on it. I will be very interested to see if you can find a solution.

11:26 PM
15 May 2009

Pieter Vanderwerff

Another quick update:
I still haven’t gotten the code just right for it to work all the time. I’m having to delve into some of the other files as well, as it seems that there’s conflicts with some of them causing problems.

I will say that it seems that even the standard one doesn’t function as well when using a BitmapRenderer. The particles miss way more often than with a DisplayObjectRenderer.

I haven’t really had much time lately to mess with this, been doing GIS work lately. I will hopefully be able to work out a solution some time soon.

10:44 AM
22 May 2009

Harrison

Hi
As you are realising, the linesandcollisions branch is very incomplete, with some code that I’ve started and not finished (like the DiscZone collisions). I checked it in because I didn’t want to lose it while working on features in other branches. If you want to use it, you need to check what zones do and don’t work with collisions.

I hope to get version 2.1 out very soon, after which I can work on the linesandcollisions again for a 2.2 release later.

5:01 AM
11 Jun 2009

Richard Lord

So far the LineZone is the only zone that i know of that is working constantly although still not perfectly. I have not tried the point zone as i have not found a use for it.

Thank you for your hard work on this, i am very much looking forward to seeing version 2.1 and even more so for the official release of the linesandcollisions branch in 2.2.

6:23 AM
11 Jun 2009

Pieter Vanderwerff

Write a Comment

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

Name

Email

Website

Comment