Page 1 of 1

ghost object is sticky, holds onto objects too long [with video]

Posted: Mon Dec 17, 2018 3:49 am
by PcChip
Hi,

I was hoping someone could help me figure out why my btPairCachingGhostObject "holds" onto a pair until it's well outside its range

I tried cleaning the proxy after each time it's moved, but that didn't seem to help
also I normally set forceUpdateAABB to false when I create the physics world, but I tried commenting that out and it didn't help

any ideas would be appreciated!


video of problem:
https://www.youtube.com/watch?v=v5lScKmKPLk

this is how I'm detecting buildings inside the ghost object:
(FYI "GlobalID" is like a GUID for each object/building in the simulation)

Code: Select all

bool TranceEngine::getAllOverlappingBuildings(btPairCachingGhostObject* myGhostObject, vector<teEntityDatabaseModule::entityIndex>& potentialBuildings)
{
	
	bool foundABuilding = false;

	btManifoldArray manifoldArray;
	btBroadphasePairArray& pairArray = myGhostObject->getOverlappingPairCache()->getOverlappingPairArray();
	int numPairs = pairArray.size();

	for (int k = 0; k < numPairs; ++k)
	{
		manifoldArray.clear();
		const btBroadphasePair& pair = pairArray[k];
		btBroadphasePair* collisionPair = physicsModule->dynamicsWorld->getPairCache()->findPair(pair.m_pProxy0, pair.m_pProxy1);
		if (!collisionPair) continue;
		if (collisionPair->m_algorithm)
			collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);

		for (int j = 0; j < manifoldArray.size(); j++)
		{
			btPersistentManifold* manifold = manifoldArray[j];
			for (int p = 0; p < manifold->getNumContacts(); ++p)
			{
				const btManifoldPoint& pt = manifold->getContactPoint(p);

				if (pt.getDistance() < 0.f)
				{
					// Object is inside ghost's shape at this manifold point
					// process shape overlap here
					int managerID1 = manifold->getBody0()->getUserIndex();
					int globalID1 = manifold->getBody0()->getUserIndex2();

					int globalID2 = manifold->getBody1()->getUserIndex2();
					int managerID2 = manifold->getBody1()->getUserIndex();

					if (globalID1 > 0)       //found a valid GlobalID
					{
						if (managerModule->managers[managerID1]->isBuilding)
						{
							potentialBuildings.emplace_back(teEntityDatabaseModule::entityIndex({ managerID1,globalID1 }));
							foundABuilding = true;
						}
					}
					else if (globalID2 > 0)  //found a valid GlobalID
					{
						if (managerModule->managers[managerID2]->isBuilding)
						{
							potentialBuildings.emplace_back(teEntityDatabaseModule::entityIndex({ managerID2,globalID2 }));
							foundABuilding = true;
						}

					}
					/*
					else
					{
						//std::cout << "invalid Target found: myGhostObject: " << myGhostObject << " body0: " << test3 << ":" << test4 << " body1: " << test1 << ":" << test2 << "\n";
					}*/

				}/*
				else
				{
					// Object is in ghost's aabb but not inside its shape at this manifold point
					// process aabb overlap here
				}*/

			}
		}
	}

	return foundABuilding; //didn't find shit

}

Re: ghost object is sticky, holds onto objects too long [with video]

Posted: Thu Dec 20, 2018 6:08 pm
by bram
Maybe it is the default 0.02 margin?

Code: Select all

virtual void btCollisionShape::setMargin 	( 	btScalar  	margin	) 	
What's the scale of those spheres? Try setting the margin to 0.001 and see if it changes.

Re: ghost object is sticky, holds onto objects too long [with video]

Posted: Wed Jan 09, 2019 1:04 pm
by teolazza
Try to clear the all manifolds related to your ghost object at each step