Arkasha
15-05-2006 11:20:19
Hello, I would like to create general collision events when there is a collision in between a Player and user created Objects. I have given them specific CollisionIDs.
I can create the event with the following code, but my problem is if the player is for example "resting" against a wall, events are continuisly generated. Is there any way of detecting a "first contact?" so I can generate only one event.
I can create the event with the following code, but my problem is if the player is for example "resting" against a wall, events are continuisly generated. Is there any way of detecting a "first contact?" so I can generate only one event.
#include "MaterialCallback.h"
MaterialCallback::MaterialCallback( void )
{
mRealCollision = false;
}
MaterialCallback::~MaterialCallback( void )
{
}
int MaterialCallback::userBegin()
{
return ContactCallback::userBegin();
mRealCollision = false;
}
// This is the method to change for new collision adjustments
// When making a new Contact callback extend from this and return this method at end
int MaterialCallback::userProcess()
{
mRealCollision = true;
return ContactCallback::userProcess();
}
void MaterialCallback::userEnd()
{
if( mRealCollision )
{
String objName0 = ( (Object*)m_body0->getUserData() )->getName();
String objName1 = ( (Object*)m_body1->getUserData() )->getName();
EventManager::getSingleton()->createCollisionEvent(objName0, objName1);
EventManager::getSingleton()->createCollisionEvent(objName1, objName0);
mRealCollision = false;
}
return ContactCallback::userEnd();
}