Game Development Community

Disabling collisions between players

by Richard Chouinard · in Torque Game Engine · 04/11/2007 (7:03 am) · 10 replies

In my game, I control two characters (AI players) with mouse clicks. I can switch characters by right clicking. I want to disable collisions between these two but not with every other object in the game. There might be enemies I will want to bump into. How can I do this?

#1
04/11/2007 (11:25 am)
Hi Richard,
You'll want to look at the Armor::onCollision method, I'd think.

Create a field called "exemptFromCollision" on your bots.

function Armor::onCollision(%this,%obj,%col)
{
   if (%obj.exemptFromCollision && %col.exemptFromCollision) {
      return(false);
   }

  //(the rest of the function is unchanged)
}

There's probably a more elegant way to do this, but without access to my home system and a few gallons of caffeine, this is the best I could come up with. =)
#2
04/11/2007 (4:40 pm)
I don't think that's going to do it. This will stop any of the script-side actions called on collision from happening, but it won't stop the collision itself (which has already happened in the engine by the time this function gets called). There is a method for disabling collision between two objects, I beieve, but I honestly can't think of what it is at the moment. =P
#3
04/11/2007 (4:50 pm)
Nah, that is not enough.

Head into updatePos () inside the polylist magic where it grabs the list, check for the type and jump out of the current loop iteration if it is a player type.

Edit: Correction, said updateMove () which is incorrect. Need some sleep.
#4
04/11/2007 (4:52 pm)
Whup! You're absolutely right, Henry!

Richard, a quick romp through the forums turns up the disableCollision() method in the source code (which is not exposed to script). There's a post by Ramen-Sama here which might put you on the right track. It doesn't appear as though you can disable collisions in script without making source code changes.
#5
04/11/2007 (4:53 pm)
Better yet, listen to Stefan. He's better-versed in all these newfangled code doohickeys than I am. =)
#6
04/12/2007 (1:09 pm)
I tried something in updatePos() in player.cc.

// Build list from convex states here...
CollisionWorkingList& rList = mConvex.getWorkingList();
CollisionWorkingList* pList = rList.wLink.mNext;
while (pList != &rList)
{
Convex* pConvex = pList->mConvex;

if (pConvex->getObject()->getClassName() == "AIPlayer")
{
start = end;
break;
}
...

Now my AIplayers just fall through the world, there is no collision anymore.
#7
04/12/2007 (1:15 pm)
Nevermind, I found what was wrong. The code to change was a little bit further.

// Build list from convex states here...
CollisionWorkingList& rList = mConvex.getWorkingList();
CollisionWorkingList* pList = rList.wLink.mNext;
while (pList != &rList) 
{
	Convex* pConvex = pList->mConvex;

	if (pConvex->getObject()->getClassName() != "AIPlayer")			
	{				

		if (pConvex->getObject()->getTypeMask() & sCollisionMoveMask) 
		{
			Box3F convexBox = pConvex->getBoundingBox();
			if (plistBox.isOverlapped(convexBox))
			{
			if (pConvex->getObject()->getTypeMask() & PhysicalZoneObjectType)
				pConvex->getPolyList(&sPhysZonePolyList);
			else
				pConvex->getPolyList(&sExtrudedPolyList);
			}
		}
	}
	pList = pList->wLink.mNext;
}

It works now, thank you.
#8
04/15/2007 (10:17 am)
And why cant he just Do a GetID of the AI Player and store it then make it uncollidable to player with Oncollision ... disabled . Nice and Simple.... Why Overwork a script :)
#9
04/15/2007 (10:50 am)
Richard,

You should avoid doing string comparasions inside functions like updatePos (), especially when you can just compare the type masks. See the if statement below your new one for an example.

I just realized something though. Scroll up to ~80 in player.cpp and remove PlayerObjectType from the list. Make sure those | match up.

That should achieve the effect you were looking for with just changing one line!
#10
04/16/2007 (11:43 am)
Thank you Stefan, that works better than my solution.