QuickBox2D groupIndex

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2. import Box2D.Common.Math.*;
  3.  
  4. stage.frameRate = 60;
  5.  
  6. var sim:QuickBox2D = new QuickBox2D(this);
  7.  
  8. sim.createStageWalls();
  9.  
  10. createTraveler(3, 3);
  11.  
  12. addObstacles();
  13.  
  14. function addObstacles():void{
  15.     sim.setDefault({groupIndex:-1, density:0, height:0.4});
  16.     sim.addBox({x:6, y:5, width:8, angle:0.17})
  17.     sim.addBox({x:7, y:7.1, width:8, angle:-0.17})
  18.     sim.addBox({x:5, y:9.1, width:8,  angle:0.10})
  19.     sim.addBox({x:6, y:11.5, width:8.9,  angle:-0.20})
  20.     sim.addBox({x:5.5, y:16, width:9, angle:0.20})
  21.     sim.addBox({x:5.5, y:18, width:9})
  22.     sim.addCircle({x:11, y:20, radius:2.5, groupIndex:1});
  23.     sim.addBox({x:16, y:19, width:2, height:2, angle:0.0, groupIndex:1})
  24. }
  25.  
  26. function createTraveler(x:Number, y:Number):QuickObject{
  27.     var parts:Array = [];
  28.     parts[0] = sim.addCircle({x:0, y:1, radius:0.25, friction:0.01});
  29.     parts[1] = sim.addCircle({x:0, y:3, radius:0.25, friction:0.01});
  30.     parts[2] = sim.addBox({x:0, y:2, width:0.3, height:1.5 , groupIndex:-1});
  31.     return sim.addGroup({objects:parts, x:x, y:y });
  32. }
  33.  
  34. sim.start();
  35. sim.mouseDrag();

One of the more advanced and useful properties of rigid bodies is the groupIndex. It allows you to specify which rigid bodies collide with one another and which rigid bodies pass through one another. This snippit demo's the groupIndex property. For more information take a look at what the Box2D manual says.

Take a look at the swf here.

This entry was posted in Box2D, QuickBox2D, motion and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Posted July 1, 2009 at 9:15 am | Permalink

    Very nice! :)

  2. Ive Sorocuk
    Posted August 5, 2010 at 6:02 pm | Permalink

    Thanks for this. I’m putting together a game where I have coins falling falling into a machine and this post came in handy in getting them to fall behind them.
    My one problem is that once I added the groupIndex to the coin, it’s skin no longer shows up. Is there any reason this would be happening?

  3. Ive Sorocuk
    Posted August 5, 2010 at 6:15 pm | Permalink

    Never mind!
    I was stuck on this for a long time but the problem was with the variable name being the same as the export name.

One Trackback

  1. [...] 9. groupIndexによる衝突判定の制御 – QuickBox2D groupIndex [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*