Game Development Community

Disabling collision - so close

by Daniel Buckmaster · in Torque Game Engine · 05/21/2007 (12:19 pm) · 12 replies

I've worked up a custom class based on Item (called Pickup), with the purpose of mounting it on other objects. For this, I need it not to collide with them. I decided to copy the setCollisionTimeout method already implemented, but not run my collision ignoring on a timer.
So I created a new field, mCollisionIgnoreObject, and I set this field to the ID of any object that the Pickup is mounted to (then clearing it again when we unMount). I searched through the code, adding mCollisionIgnoreObject->enable/disableCollision() calls whenever the same call is made on mCollisionObject (in a separate 'if' clause, of course).
However, my Pickup objects still collide with objects they have been mounted to. I'm wondering what I've done wrong - the code compiles without errors or warnings.

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!


#1
05/21/2007 (12:35 pm)
Wibble. That sounds like a really hard way to turn off collisions.

What you actually want to do is thus [this is taken from item.cc]:

const U32 sClientCollisionMask = (TerrainObjectType     | InteriorObjectType |
                                  StaticShapeObjectType | VehicleObjectType  |
                                  PlayerObjectType      | StaticTSObjectType);

const U32 sServerCollisionMask = (sClientCollisionMask);

That probably appears somewhere in your code. Take out the PlayerObjectType. Now when *it* does collisions, it won't find that players collided with it. There's countless examples in the code of how stuff like this gets used.


Now scroll down and find where you set your object's mTypeMask. In Item's Constructor, you'll find this:
mTypeMask |= ItemObjectType;

To make *players* not collide with your object, a fast copout is to make sure that is unset in your constructor, /a la/
mTypeMask &= !ItemObjectType;

What you should *really* do is make a new type, PickupObjectType [just grep the source for all those other ObjectTypes, and add a new one] and set your mTypeMask appropriately.

Gary (-;
#2
05/21/2007 (10:07 pm)
The problem is, I do want it to collide with Players usually, but only not to collide when it's mounted. Unless there's a way to dynamically change the collision mask...
#3
05/21/2007 (11:18 pm)
Sure there is, Just scroll down to where that mask is actually used, and throw in a simple check.

From item.cc again:
updateWorkingCollisionSet(isGhost() ? sClientCollisionMask : sServerCollisionMask, TickSec);

You'll just want to change that to something like this:
U32 colmask = isGhost() ? sClientCollisionMask : sServerCollisionMask;
if(isMounted()) {
   colmask &= !PlayerObjectType;
}
updateWorkingCollisionSet(colmask, TickSec);

Gary (-;
#4
05/22/2007 (10:16 am)
Huh, the things you learn! Thanks very much for the help. I'll be back shortly with a progress report. :)
Would I be able to do something like replace the PlayerObjectType with a whole mask definition, so that I can specify multiple types of objects to ignore collision with? Maybe a more elaborate check that just subtracts the object type that the Pickup is mounted to.
#5
05/22/2007 (10:33 am)
Sure, you could do all sorts of craziness there if you really wanted. No harm in trying, right? :-)

Gary (-;
#6
05/22/2007 (10:44 am)
Well, I tried what you had above, and it doesn't seem to work.
I added a 'Pickup' into the Barebones mission with a simple datablock. I defined an onCollision method for it which just echoes something to the console. I unmounted the Player's default crossbow using unMountImage, then did stuck the Pickup to the player with mountObject. Nothing happens until the player moves again, at which point the Pickup's onCollision gets called every half second or so, even if the player then stops moving.
(This is the same behaviour I got with my jerry-rigged system, but for the record I removed all that before trying your modification.)
#7
05/22/2007 (12:10 pm)
First, are you sure it's colliding with the player? In your onCollision method, check what %obj is.

You may also be missing a sprinkling of updateContainer(); ?

Gary (-;
#8
05/23/2007 (11:11 am)
Yep. I echoed %col.getClassName() and it came up as Player.

I'll have a look at the source, but I don't know what updateContainer does. I'm new to this stuff :P.
#9
06/01/2007 (1:11 pm)
Okay, I really don't like to bump. But I really need an answer to this problem. I'd really like to know why my first method didn't work when it's implemented exactly the same way as the existing collision ignore system, and what's wrong with Gary's suggestion.
#10
06/01/2007 (1:49 pm)
There is never anything wrong with Gary's suggestions.
#11
06/02/2007 (4:47 am)
Well, the Pickup, once mounted, still collides with the Player. I'd like for this not to happen. I'm not doubting Gary as a person, I'd just like a little help with this.

:)... sort of
#12
06/04/2007 (10:59 am)
Okay, I managed a hack. I added a boolean parameter in setCollisionTimeout, basically asking whether to time the object out or not. If not, it just uses he setCollisionTimeout system to ignore the object indefinately. I'm rather pleased - this was my first time moding an existing method, and working with console methods. However, I still wonder why my method didn't work. Looking at the changes I had to make to get this way to work, I think pack/unpackUpdate had something to do with it. Maybe.