Maybe this will help. I know how frustrating collision detection can be. Even though it is supposed to be easy it can be really hard to figure out in the beginning. I am working on a game that also has a ball an uses collision detection. I will post the vast majority of my collision detection code below:
For my collisions I use a MetaSelector because I have many objects I want to collide the ball with. Here is that code. I will just show only one of the selectors added to my meta selector for the sake of not having tons of code. A MetaTriangleSelector is just a group of triangleSelectors that act exactly like one.
*Note this is done before the main event loop and before the collision detection code of the ball
Code: Select all
scene::IMetaTriangleSelector* metaSelector = irrSceneMgr->createMetaTriangleSelector();
scene::ITriangleSelector* selector = irrSceneMgr->createOctTreeTriangleSelector(outerWallMesh->getMesh(0),outerWallNode,128);
metaSelector->addTriangleSelector(selector);
Now your wall or anything else you stuck in the MetaTriangleSelector is ready for collision. So now you need to set up collision detection for the ball. This is done by adding a collisionResponseAnimator to the object that will be colliding with the rest of your scene. This is done in my code as follows. My ball Node is called is called ps4.
*Note: this is done before the main event loop and after the creation of the metaTriangleSelector.
Code: Select all
scene::ISceneNodeAnimator* anim2 =
irrSceneMgr->createCollisionResponseAnimator(metaSelector,ps4, core::vector3df(6,6,6), core::vector3df(0,0,0), .01f, core::vector3df(0,5,0));
ps4->addAnimator(anim2);
anim2->drop();
*Note the first vector in the createCollisionResponseAnimator is how far around the ball collision dectedtion will be detected. For my ball vector3df(6,6,6) worked but yours may be much bigger or much smaller than mine so you will probibly have to adjust that.
And that is all you have to do. I hope this works for you!
I hope this works for you but maybe not. If it does not I am sorry but it worked for me exactly as I typed it so it should work for you!