Game Development Community

Can I do this with collision??

by Firas · in Torque Game Builder · 09/26/2006 (2:20 am) · 5 replies

Hi guys

I wont to modify my collision properities in real time as following:

If Object A touch (collide) with Object B a collision should occur or trigger between A and B.
If Object A touch (collide) with Object C no collision occur or trigger between A and C.

how to do this?

any help please.

#1
09/26/2006 (2:29 am)
You can set collision layers for the objects. For example:
Put Object A on layer 1, and have it collide with layer 2.
Put object B on layer 2 and have it collide with layer 1.
Put object C on layer 3 and disable collisions.

That's a pretty simple description, but it should do the job. Try working through the collisions tutorial in the documentation as well.
#2
09/26/2006 (3:17 am)
Thanks philip I check the collision tutorial and it help a lot but I have a couple of questions:

1- how can I set my collision layer using script?

2- what is the difference between group and layer?

I know it maybe a simple question but I'm still begines here.

thanks inadvance.
#3
09/26/2006 (4:17 am)
There are two participants of every collision in TGB: sender and receiver. For a collision to register between two objects, one has to have collisionActiveSend set to true, and the other has to have collisionActiveReceive set to true. This is where the collision layers and collision groups come in to play. In addition to the above, two more conditions must be met for a collision to occur: the layer of the receiver must be in the collisionLayers of the sender, and the graphGroup of the receiver must be in the collisionGroups of the sender.

By default, all objects have collisionLayers and collisionGroups on for all layers and graphGroups. Assuming one object is only set to be actively sending collision (and not receiving), if you remove a graphGroup from the sender it will no longer actively register collisions with objects in that group - regardless of whether or not the receiver's layer is in the sender's collisionLayers. That makes groups best suited for collision masks because you don't have to move objects between layers and potentially muck up your scene (visually) to mask collisions how you want to.

That's the basic lowdown on layers and groups in terms of collision.

For information on how to manipulate collision settings via script, check out this page.

Edit: SP
#4
09/26/2006 (7:47 pm)
I would like to chime in and say how important the following point Thomas made really is:
Quote:By default, all objects have collisionLayers and collisionGroups on for all layers and graphGroups.

I wasted a lot of time not having any success with my collisions until this sunk in for me.

This works for me, your mileage may vary:

I now make it a rule when I am creating any objects in script that I always assign a layer and graphGroup to these objects.

This way, by default, since the collision groups/layers are empty to start with (equivalent to BIT(0) I believe) NONE of your objects will collide with each other, which is the opposite effect of the default settings.

Once my objects are created, and assigned layers, I use a plain ordinary paper pad to design out, which objects will be sending, recieving, or both collisions. Then I determine, based on the desired mechanics of the game or simulation, which objects need to collide with each other.

Once this is done, I translate the above into each of the objects by setting the collision Groups and Layers. I also wasted a bit of time figuring out that using the BIT() and BITS() functions were essential in making these work. (Wrong, See below, sorry).

Anyhow, just my 3cents worth.

Correction: I thought I was using BIT() and BITS() functions in the collision Groups and Layers, Actually it is just a List such as "1 2 3", these other functions were used for something else.
#5
09/28/2006 (1:35 am)
You can use BIT for setCollisionMasks. You also need to use BIT when you assign collisionGroups and collisionLayers fields on an object (either when creating it via script, or assigning the value via a datablock).