Overriding material callback userProcess

atsakir

22-03-2006 16:52:37

I have billboarded grass and I want to affect the velocity of my character when he passes through the bounding volume of the grass.

I have asked about this before and was prompted by walaber to setup a collision callback. I used Tutorial3 as a guide and set up the following userProcess in which I always return 0 (reject the collision) and cut the velocity to half. However, the collision still bounces my character against the bounding volume of the grass instead of passing through with half the velocity. What am I doing wrong? Should I override the contactProcess instead of the userProcess?


int grassMatCallback::userProcess()
{

OgreNewt::Body* grass;
OgreNewt::Body* object;

if (m_body0->getType() == mGrassID)
{
Ogre::LogManager::getSingleton().logMessage(" COLLISION 0");
grass = m_body0;
object = m_body1;
}

if (m_body1->getType() == mGrassID)
{
Ogre::LogManager::getSingleton().logMessage(" COLLISION 1");
grass = m_body1;
object = m_body0;
}

if (!grass) {
Ogre::LogManager::getSingleton().logMessage(" NO COLLISION ");
}

object->setVelocity(object->getVelocity()*0.5);

return 0;
}

walaber

22-03-2006 17:29:35

that should work. are you certain that you are setting the materials properly on the bodies, and that the material callback is being called?

also you should know that userProcess gets called for every contact between the 2 bodies, so in a single call to World::update() you might get it called 2-4 times for a single set of bodies. this would mean your object would slow down to 1/4 or 1/8 of it's original speed. if might be smarter to just store a flag for the *first* time the bode hits the grass, and only slow it down then.

atsakir

23-03-2006 09:27:16

the material for the grass is applied the same way as the conveyor belt, the character (the same way as the boxes in tut3) keeps the default material and the logging shows that the callback is called when my character and an object with grass material ID collide. Apparently, it was the

object->setVelocity(object->getVelocity()*0.5);

to blame because taking it out ignores the collision correctly

walaber

23-03-2006 15:58:26

like I said... implement a flag, and apply the damping after update() has finished, based on the data you gather from the callbacks...

I guess messing with velocity in the contact callback is a no-no :)