RayTest btConvexHullShape fails

Post Reply
paokakis
Posts: 29
Joined: Mon Jan 04, 2021 10:31 am

RayTest btConvexHullShape fails

Post by paokakis »

I am developing a 3D space shooter game using bullet physics. I have a crosshair in the middle of the screen and I am ray testing from the center of the screen to the camera far vector in bullet to get the first collision object in that ray. If the object is a sphere or a box the test is very accurate and successful. If the object is a convex hull shape then the ray test fails 90%... Here is my code :

Code: Select all

bool BphysicsManager::rayHasHit(glm::vec3& rayFromWorld, glm::vec3& rayToWorld, btVector3* hitPointWorld, btRigidBody** body)
{
	mMutex->lock();
	bool ret;
	rayFrom.setX(rayFromWorld.x);
	rayFrom.setY(rayFromWorld.y);
	rayFrom.setZ(rayFromWorld.z);

	rayTo.setX(rayToWorld.x);
	rayTo.setY(rayToWorld.y);
	rayTo.setZ(rayToWorld.z);

	btCollisionWorld::ClosestRayResultCallback rayCallback(rayFrom, rayTo);
	mpDynamicsWorld->rayTest(rayFrom, rayTo, rayCallback);

	if (rayCallback.m_collisionObject)
	{
		*body = (btRigidBody*)btRigidBody::upcast(rayCallback.m_collisionObject);
		*hitPointWorld = rayCallback.m_hitPointWorld;

		auto colShape = (*body)->getCollisionShape();
		if (dynamic_cast<btConcaveShape*>(colShape) != nullptr)
		{
			*body = nullptr;
		}
	}

	ret = rayCallback.hasHit();
	mMutex->unlock();

	return ret;
}
Am I doing something wrong with the convex hull shape or is it a bullet problem? Can I do something to improve it?
paokakis
Posts: 29
Joined: Mon Jan 04, 2021 10:31 am

Re: RayTest btConvexHullShape fails

Post by paokakis »

It was my problem. My object had multiple meshes so multiple convex hulls were added. After debug drawing I could see the convex hulls and were able to ray test them. So it is solved
Post Reply