Game Development Community

Disabling collision

by Daniel Buckmaster · in Torque Game Engine · 04/29/2007 (12:35 pm) · 7 replies

I've just got my Item-derived custom class working, and it'll mount to the Player beautifully. However, if the player subsequently moves, the mounted object will collide with it every half-second or so. I don't want that to happen, so I'm wondering what I can do about it. I tried putting a call in the onMount function to disableCollision(), but that had the nasty side-effect of making my object totally disappear when collided with. I tried setting mCollidable to false, but that had no effect.
Can someone throw me a bone?

About the author

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


#1
04/29/2007 (1:27 pm)
I did something similar, but based my class on shapebase. Didn't need all the added functions in item. You have two options depending on what you need. Both are rather simple.

1) Give your new class a different collision mask bit.
2) In player.cpp, look for the disable/enable collision functions. You'll see that it simply calls the shapebase version of it. Add code here to disable/enable collisions with the object you just mounted.

object = this->getMountedObject([i]slot#[/i]);
object->disableCollision();
#2
04/30/2007 (11:03 pm)
Quote:1) Give your new class a different collision mask bit.
How would I go about doing this? I think it'd be the most convenient way - so I can have Players not collide with the things, but projectiles etc., will. I've found objectTypes.h, where lots of these types are defined, but I suspect it's not as simple as adding my type there...
#3
05/01/2007 (3:05 am)
Actually it is. Simply define a new bit in that file, shifting bits down as you need.

MyNewObjectType =    BIT(27),

Then in your class file have it use that new bit.

mTypeMask |= MyNewObjectType;

At this point nothing will collide with your mounted object. Your player will be able to move freely about. Makes sense to do it this way, as only moving objects generate collisions. Your new object, while mounted to the player doesn't really move. It simply adopts the transform of the player it's attached to.
#4
05/01/2007 (10:01 am)
I'll try this out later, but for now one last question: will the player still be able to collide with the object to pick it up? The way I do it now is that when the player collides with the object, it's mounted in the player's hands. I do want it to collide when it's on the ground, but not after being mounted.
Thanks for the help with this so far.
#5
05/01/2007 (11:47 am)
No he will not. You can either use the disableCollision method, or just spawn a regular item for collision but then create and mount your subclassed version when he runs over it. If you're going to do that, it would probably be best to subclass shapebase or a staticshape rather than item. You don't really need the item spinning in circles on the character or any of the other functionality within the item class.
#6
05/02/2007 (8:25 am)
Well, using the Item class was because I wanted its physical interaction with the world (dropping, bouncing, being pushed by explosions). I created the subclass with mounting because I wanted to get totally away from the ShapeBaseImage way - pick up an Item, delete the Item, mount an Image.
Looks like I'll go with disableCollision. When is the correct time to call this? When I tried to do it from the item's onMount function, it made the item disappear.
#7
05/06/2007 (12:01 am)
All right, I figured out another way. I looked into the way Item implements its srtCollisionTimeout method, and decided to just use the mCollisionObject field for this as well. In onMount, I set mCollisionObject to the object that is mounting the pickup, and it works fine. No more collisions while the pickup is being mounted. Hoever, what should I pu in onUnMount? I've tried setting mCollisionObject to 0, just doing a setCollisionTimeout, etc., but I get really strange behaviour (namely: flying up into the air then popping back to the Player's hands and starting to register collisions). The first variant of this code I tried had the most desireable results in that the pickup dropped to the ground from the Player's hands, but the problem was that the Player then couldn't pick it up again.