How to get an accurate collision normal?

SteveDeFacto
Posts: 31
Joined: Sat Jul 23, 2011 4:24 pm

How to get an accurate collision normal?

Post by SteveDeFacto »

I've been using a collision callback to detect when my character is on the ground. The problem is that the normal returned by m_normalWorldOnB is faulty and sometimes returns a bad normal. This allows a player to climb up slopes which they should not be able to. How can I get an accurate collision normal?

Code for my callback below:

Code: Select all

struct onGroundCheck : public btCollisionWorld::ContactResultCallback
{
	virtual	btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, int index0, const btCollisionObject* colObj1, int partId1,int index1)
	{
		if((cp.m_normalWorldOnB.getY() * OvglPi) > OvglPi - maxSlope)
		{
			onGround = true;
			((btRigidBody*)colObj0)->setFriction(3.0f);
		}
		else
		{
			onGround = false;
			((btRigidBody*)colObj0)->setFriction(0.0f);
		}
		return 0;
	}

	float maxSlope;
	bool onGround;
};