Actionscript:
-
import com.actionsnippet.qbox.*;
-
import Box2D.Common.Math.*;
-
-
stage.frameRate = 60;
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
sim.createStageWalls();
-
-
createTraveler(3, 3);
-
-
addObstacles();
-
-
function addObstacles():void{
-
sim.setDefault({groupIndex:-1, density:0, height:0.4});
-
sim.addBox({x:6, y:5, width:8, angle:0.17})
-
sim.addBox({x:7, y:7.1, width:8, angle:-0.17})
-
sim.addBox({x:5, y:9.1, width:8, angle:0.10})
-
sim.addBox({x:6, y:11.5, width:8.9, angle:-0.20})
-
sim.addBox({x:5.5, y:16, width:9, angle:0.20})
-
sim.addBox({x:5.5, y:18, width:9})
-
sim.addCircle({x:11, y:20, radius:2.5, groupIndex:1});
-
sim.addBox({x:16, y:19, width:2, height:2, angle:0.0, groupIndex:1})
-
}
-
-
function createTraveler(x:Number, y:Number):QuickObject{
-
var parts:Array = [];
-
parts[0] = sim.addCircle({x:0, y:1, radius:0.25, friction:0.01});
-
parts[1] = sim.addCircle({x:0, y:3, radius:0.25, friction:0.01});
-
parts[2] = sim.addBox({x:0, y:2, width:0.3, height:1.5 , groupIndex:-1});
-
return sim.addGroup({objects:parts, x:x, y:y });
-
}
-
-
sim.start();
-
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.
4 Comments
Very nice!
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?
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.
Hi,
I have sim with clpuds, planes and hero. Hero and planes should not collide with clouds, but planes should collide with hero. If I set groupIndex:-1 for hero and clouds, and -2 for planes, planes collide with clouds. If i set groupIndex -1 for hero and planes, and -2 for clouds - hero doesn’t collide with planes, but with clouds. If I set different groupIndex for planes, hero and clouds - they all collide each other.
What i need is than planes don’t collide each other, same for clouds; hero collides planes but doesn’t collide clouds.
How can i do this ?
One Trackback
[...] 9. groupIndexによる衝突判定の制御 – QuickBox2D groupIndex [...]