Trying to understand collision groups and layers
by Philip Mansfield · in Torque Game Builder · 03/03/2005 (8:43 am) · 8 replies
I've been looking at the sample code trying to figure out how to setup my collision groups and layers, but I'm not really sure what rules I'm supposed to be following when setting them up.
Here's what I think so far:
There are no bulletCollisionLayers, as the default is all layers, and I want the bullets to hit both layers.
I think I also need an entry for the ground, so I can manage collisions between it and the bullets and players. Can I use:
Or is there an easier way to write it?
Being a novice coder, it takes me a while to work this stuff out, but if someone could give me an explanation as to how these things should be organised, I reckon I'll be good to go.
Thanks.
Here's what I think so far:
item group layer player1 1 1 player2 2 1 p1bullet 3 2 p2bullet 4 2 ground 5 2 $player1CollisionGroups= BIT(4)|BIT(5); $player1CollisionLayers= BIT(2); $player2CollisionGroups= BIT(3)|(5); $player2CollisionLayers= BIT(2); $p1bulletCollisionGroups= BIT(2)|BIT(5); $p2bulletCollisionGroups= BIT(1)|BIT(5);
There are no bulletCollisionLayers, as the default is all layers, and I want the bullets to hit both layers.
I think I also need an entry for the ground, so I can manage collisions between it and the bullets and players. Can I use:
$groundCollisionGroups=BIT(1)|BIT(2)|BIT(3)|BIT(4)|BIT(5);
Or is there an easier way to write it?
Being a novice coder, it takes me a while to work this stuff out, but if someone could give me an explanation as to how these things should be organised, I reckon I'll be good to go.
Thanks.
#2
Am I right in assuming that the Group is like the parent object and has many layers?
03/03/2005 (9:14 am)
Thanks, that helps tidy up how should I be naming things to keep it readable, but I'm still not clear on how you decide which items need to go into which groups and layers.Am I right in assuming that the Group is like the parent object and has many layers?
Group 1 + Layer1 + Layer2 + Layer3
#3
A group defines the type of an object in terms of collisions.
You want bullets to hit players, but you don't want bullets to hit flowers (for example). So you'd put players into a group, bullets into a group, and flowers into a group. Then you'd tell the engine to do something when players and bullets touch, but not when bullets and flowers touch (based on the "collision mask" group settings).
Layers are like distinct collections of objects from any group.
Objects on layer 1 (for example) can be controlled to not interact with any other layers or only specific other layers (based on the "collision mask" layer settings). If two objects are in the same layer, then the engine will look at their groups and determine their interaction from that.
Hope that helps!
03/03/2005 (9:57 am)
Groups and layers are two distinct tools for categorizing your objects.A group defines the type of an object in terms of collisions.
You want bullets to hit players, but you don't want bullets to hit flowers (for example). So you'd put players into a group, bullets into a group, and flowers into a group. Then you'd tell the engine to do something when players and bullets touch, but not when bullets and flowers touch (based on the "collision mask" group settings).
Layers are like distinct collections of objects from any group.
Objects on layer 1 (for example) can be controlled to not interact with any other layers or only specific other layers (based on the "collision mask" layer settings). If two objects are in the same layer, then the engine will look at their groups and determine their interaction from that.
Hope that helps!
#4
03/03/2005 (10:20 am)
OK, that helps clear things up a bit, but don't let that stop anyone else from posting explanations/hints ;)
#5
09/04/2007 (11:42 pm)
This has informed me a bit more with the collision system; but how would one remove a mask on-the-fly(using bitwise :/ )?
#6
this will remove flag from mask if it was present.
09/05/2007 (3:33 am)
Just do a mask = mask & ~flagthis will remove flag from mask if it was present.
#7
09/08/2007 (6:50 pm)
Thanks a ton man, that really helps. Any chance you know the bit code for a NULL(no flags set) mask?
#8
09/08/2007 (7:26 pm)
0 (zero) :) (as in the value, not the bit position)
Torque Owner Jason McIntosh
Then you can refer to the names instead of the numbers, and things are more clear both now while you're building it and later when you need to change something and have forgotten what those numbers mean. So instead of just BIT( 1 ), you would have BIT( $COLLISION_GROUP_PLAYER ), for example.
You probably still want to specify each layer, just in case things change later and you have something you don't want the bullets to hit. So you'd do (substituting for all the appropriate group variables/values):
If you want the ground to collide with everything, you can do
To keep things more readable, you should create a global for the "all" bitmask:
Keep at it, and it will click eventually. :)