Game Development Community

How to easily disable a single collision layer?

by StickFigs · in Torque Game Builder · 08/09/2007 (7:35 pm) · 9 replies

I'm trying to find out how I can easily disable collisions with layer 2 for a certain object in a script, and then how to add layer 2 back. The only functions I can find in the reference force me to specify all the layers again and I was wondering if there was an easier way or not. And if there isn't how do I use the setCollisionLayers() function to do what I just described?

#1
08/10/2007 (9:00 am)
I don't know if there is a method to disable a specific collision layer, but if you wanted to turn off collisions with layer 2 and then go back to the way it was you could use getCollisionLayers() to store the collision layer information.

ie
%temp = %this.getCollisionLayers();
//now set layer 2 to disabled
%temp = %this.setCollisionLayers(0 1 3 4...);
...
code happens here
...
//reinstating old collision layer settings
%this.setCollisionLayers(%temp);
#2
08/10/2007 (11:14 am)
Why would I want to set %temp to the old settings and then immediately overwrite them with "%temp = %this.setCollisionLayers(0 1 3 4...);"?
#3
08/10/2007 (11:19 am)
Oops I meant to just %this.setCollisionLayers(...); Copy paste is not my friend.
#4
08/10/2007 (11:23 am)
EDIT: I don't know why this posted twice, but...

It appears using:

$player.setCollisionLayers(0,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);

...makes the game crash. :(
#5
08/10/2007 (11:25 am)
Try taking out the commas?
#6
08/10/2007 (11:32 am)
Codeweaver is giving me problems if I don't use commas, and if I take them out then it appears the object decides not to collide with any layers.
#7
08/10/2007 (11:37 am)
EDIT: Oops, I guess refreshing the page makes it re-post again.
#8
08/10/2007 (11:40 am)
Ooo! Try "0 1 2 3 4..."...in quotes, as shown in the reference guide example, which I should have looked at to begin with:
tdn.garagegames.com/wiki/Torque_2D/Reference_Guide
#9
08/10/2007 (11:45 am)
Ah, thanks! Now it works perfectly. :)