[SOLVED]collision and materials

smirnof.pl

18-04-2006 16:55:03

Hello,
I have question about collisions betwen objects. I know if I want to add event (for example - sound when box hit the ground) I have to use material callbacks and these functions: userBegin(), userProcess(), userEnd(). But I dont know how to check in userBegin() or in userProcess() if m_body0 and m_body1 collided. My userBegin() and userProcess() allways return 1, so userEnd() is executeted when objects are not collide but their AABB overlap. It cause that event sound is played when objects not collide.
I hope you can understand my problem :)

thanks in advance

walaber

18-04-2006 18:26:53

basically there are 3 possible scenarios:

1) The 2 bodies do not collide at all:
Result: no callbacks are called.

2) The 2 bodies' AABB overlap, but there is no "true" collision.
Result: userBegin() is called, and then userEnd() is called.

3) The 2 bodies collide.
Result: userBegin() is called, then userProcess() for each contact, and finall userEnd().


so, if you only want to play a sound for scenario #3, you need to make note that userProcess() was called.
the simplest thing is to make a variable

void userBegin()
{
mRealCollision = false;
}


void userProcess()
{
// this is a "real" collision
mRealCollision = true;
}


void userEnd()
{
if (mRealCollision == true)
{
// play sound!
}
}

smirnof.pl

18-04-2006 20:07:05

Thanks!! I didn't know that userProcess() is called only in real collision.
You are my hero, thanks again :D