Game Development Community

CollisionLayers in Datablocks don't work

by MrSpaceGame · in Torque Game Builder · 05/05/2012 (5:18 pm) · 4 replies

datablock t2dSceneObjectDatablock(PlayerConfig)
{
   canSaveDynamicFields = "1";
   Layer = "1";
   size = "4 7";
   CollisionLayers = "0 1 2";
   CollisionActiveSend = "1";
   CollisionActiveReceive = "0";
   CollisionPhysicsReceive = "0";
   CollisionPhysicsSend = "1";
   CollisionCallback = true;
   CollisionPolyList = "-0.57 -0.59 0.68 -0.59 0.67 0.96 -0.55 0.96";
   CollisionResponseMode = "CLAMP";
   CollisionDetectionMode = "CIRCLE";
   CollisionCircleScale = "0.6";
   UsesPhysics = "1";
   AutoMassInertia = true;
   Rotation = "0";
   WorldLimitMode = "CLAMP";
   WorldLimitMax = "50 38";
   WorldLimitMin = "-50 -38";   

};

That's my datablock.
When I execute "echo($Player.getCollisionLayers());" ingame on the console, it returns nothing and collisions don't work.
When I use $Player.setCollisionLayers() everything is fine.
For me, that's a bug. If I am wrong feel free to move it :).

#1
05/05/2012 (6:21 pm)
Actually I do believe collision layers are stored as a single binary value. I forget how it goes exactly though. You might want to set the collision layers in the scene editor on a test object, then echo the collision layers of that to figure out what the value has to be.

Edit: No sorry, not binary. It is one single decimal value, that is interpreted as a binary value (like on/off switches for each layer)
e.g.

1 = 1
2 = 2
3 = 1 2
4 = 3
5 = 1 3
6 = 2 3
7 = 1 2 3
8 = 4

etc. (And -1 = All )

Edit2: I just remembered getCollisionLayers() and setCollisionLayers() will deceive you, because they automatically convert the single value into a list of layers and vice versa, respectively. So even though echoing "getCollisionLayers" will show you a list of layers that are turned on, the actual value for that field will be something different.
#2
05/05/2012 (6:30 pm)
When I do it via the setter, I do it this way:

$Player.setCollisionLayers("0 1 2 3");

edit:
Actually this does not work correctly..
#3
05/05/2012 (9:45 pm)
I think the syntax is something like:

CollisionLayers = BIT(#);
#4
05/21/2012 (4:11 pm)
Okay, the correct way is:

$Player.CollisionLayers = BIT(0) ^ BIT(1) ^ BIT(2) ^ BIT(3);