The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Page 1 of 5 123 ... LastLast
Results 1 to 15 of 64

Thread: Collision Detection Kit

  1. #1

    Collision Detection Kit

    Hello Kirupians!

    Recently I had a need for shape-based collision detection and decided to write up a class to handle it. As the class developed, I discovered other things that would be nice to have but weren't available, so I worked it out and added the functionality to my class.
    Long story short, it developed into a small package of code I call the Collision Detection Kit. It's been so useful for me that I've decided to put it under an MIT license and share it with all of you.
    It uses bitmapdata to find overlapping pixels of display objects. Not a new idea, I realize, but I wrote mine out from scratch anyways to handle things the way I needed them handled. This allowed me to figure out a few other nifty features that I include in the kit. Here are the big ones that me and my beta testers/coworkers have been loving:

    - Set an alpha threshold so that any pixels on a display object below that alpha won't be checked for collisions.
    - Exclude colors and color ranges from collision detection.
    - The kit can approximate the angle of a collision, allowing you to keep your physics convincing when colliding with odd/organic shapes. It took awhile to figure out a good way of doing this. It's my favorite part of the kit.
    - Gives you the pixels that overlap in a collision in stage coordinates, making it easier for you to adjust positions or apply off-center rotation convincingly.
    - The kit takes nesting into account, so it doesn't matter where your display objects are on the display list.
    - Takes transforms into account for individual instances, so things like scaling, rotating, and performing color transforms on your objects are no problem. This includes transformation made to any parent containers!
    - Can be used with display objects on or off the display list. Works great alongside blitting engines.
    - Works with all display objects: MovieClips, Sprites, TextFields (very cool), FLVs, etc.

    I've created pre-compiled examples to show off these features and give you a better idea of what this package is capable of doing. I also have all classes documented, available online and for download (includes some rudimentary source code examples).
    Feedback is welcomed! I don't have a discussion list for this yet, but plan on adding that or a forum later this evening (via Google Code). In the meanwhile, post any questions you might have here. I hope this can help some people out, as it's helped me a ton!

    A new version of the CDK (v1.5) is now available! Links have been updated. I'm thrilled that the CDK has been so useful to so many devs, and I'm glad to finally be pushing out this update based on user feedback. Enjoy!

    THE CODE
    EXAMPLES
    DOCUMENTATION
    Last edited by skineh; June 6th, 2009 at 04:21 PM.
    Vectorization Package - Convert raster to vector at runtime in the Flash Player!

    Collision Detection Kit - Shape-based collision detection package for AS3.

  2. #2
    Wow, nice work bud, I'm impressed. Nasty graphics, but a superb little collision engine

    Thanks for sharing it.

  3. #3
    Haha, yeah, the graphics were definitely not a focal point.

    You're welcome!
    Vectorization Package - Convert raster to vector at runtime in the Flash Player!

    Collision Detection Kit - Shape-based collision detection package for AS3.

  4. #4
    wow that's mighty impressive!

  5. #5
    Nice work dude ... Much appreciated

  6. #6
    Thanks, guys. Glad you like it!
    Vectorization Package - Convert raster to vector at runtime in the Flash Player!

    Collision Detection Kit - Shape-based collision detection package for AS3.

  7. #7
    wonderful
    thanks.i m use it

  8. #8
    Looks awesome!
    Will check it out at once.

  9. #9
    1,532
    posts
    I make half sense
    I want your baby!!!!
    Click my sig.

  10. #10
    Hahaha, thanks guys! My babies are in high demand, so might have to put you in a queue. Really, though, glad to hear you all like it! It's been a busy week for me, but I'm going to get a forum put up for it on Google Code soon in case anyone has any questions and so on.
    Vectorization Package - Convert raster to vector at runtime in the Flash Player!

    Collision Detection Kit - Shape-based collision detection package for AS3.

  11. #11
    That's amazing!
    COLOURlovers | Member #2 of the kirupa XBox 360 Club
    "I think most people would agree that your computer breaking is a Christmas miracle." ~shane-c to Timmytots

  12. #12
    I'm surprised this hasn't had even more feedback actually.

    It's great. The only thing I would say so far is find ways to optimise performance, for the amount of objects that were active, it seemed a TAD cpu heavy.

    When I've got time, I'm going to play around with it, and find ways to implement it.

  13. #13
    Thanks for the feedback Esherido, rumblesushi.

    Yea, rumblesushi, I agree there's probably room for optimization. It went through several phases of redesign along the way, and a few cheap tricks were incorporated into some of the math to get some small increases in performance. Still, there's always room for improvement! If you end up doing anything with the package (especially if you rewrite it and get it to perform faster), I'd love to hear about it!

    I should note that performance will also depend heavily on what features you're implementing. Color exclusion is the most CPU-intensive, as the bitmapdata samples taken for comparison have to perform significantly more checks against their pixel information to see if they fall under the color ranges a user has specified.
    Vectorization Package - Convert raster to vector at runtime in the Flash Player!

    Collision Detection Kit - Shape-based collision detection package for AS3.

  14. #14
    213
    posts
    Registered User
    It wouldn't hurt to include some source code examples of how to use it, like for the examples or something.
    More specifically examples showing how the various features that it has are useful for shaped based collision detection.

  15. #15
    There are several source code examples for the CollisionGroup and CollisionList classes in the documentation (as mentioned in my first post).
    Vectorization Package - Convert raster to vector at runtime in the Flash Player!

    Collision Detection Kit - Shape-based collision detection package for AS3.

Page 1 of 5 123 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012