Page 1 of 2

Collision detection not responding

Posted: Sat Feb 21, 2004 4:54 pm
by WromthraX
I had my question posted on 'Begginer Help' forum ( http://irrlicht.sourceforge.net/phpBB2/ ... php?t=1380) but I've not been able to solve the problem.

Apparently everything in the code is ok, but collision detection doesn't work at all. Also, it works with FPS camera but with my scenenode that is acting like a player in the game it doesn't.

So... if someone has time to check my code for errors again :), because I have tried everything and I get the same results.

Or.. if someone wants to write a tutorial or something like that about collision detection, that will WORK :)

Bye all.

Posted: Sat Feb 21, 2004 7:28 pm
by thesmileman
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!

Posted: Sun Feb 22, 2004 10:10 am
by VeneX
My problem with collision detection: When I move the camera to al hill, it slides slowly back to a lower level of the terrain, ok it is normal but how to solve this problem?

Thanx in advance.

Posted: Sun Feb 22, 2004 9:20 pm
by thesmileman
I guess this is the effect of gravity without taking in to account friction. I am not really sure how to solve it maybe you should ask niko about it.

Posted: Mon Feb 23, 2004 10:16 am
by Guest
Thank you for your answers thesmileman, I'll try rewriting the code following the instructions you gave me, I think i did it just as you wrote but it won't work, maybe I missed something or maybe there is some error with models I made.

I'll post the result here :)

Tnx for help again!

Posted: Mon Feb 23, 2004 10:19 am
by WromthraX
That was me above :)

Posted: Mon Feb 23, 2004 3:21 pm
by thesmileman
I really hope it helps

Posted: Thu Feb 26, 2004 11:41 pm
by Cal'Mihe
Hello all, I'm new here, I just wanted to post and let you know that I was having a similar problem and the code pieces and examples here helped me solve it :)

So thank you :D

Posted: Fri Feb 27, 2004 2:07 am
by thesmileman
Glad to hear it Cal'Mihe.

Posted: Wed Mar 24, 2004 5:36 pm
by ZDeveloper
@Venex: Try to set up the gravity to 0,0,0. I have done it and it works.

@WromthraX: Don't forget to set up the right radius. (Sorry I don't read all what you wrote, but I had a problem with radius)

I hope I could help.

collision response

Posted: Thu Mar 25, 2004 1:50 am
by Liamx
Hi.
I have a question about the game with the ball and the wall.

I'm also making a game with those objects but I want to figure out how to make the ball automaticaly bounce against the wall.

I mean, I can make the 3Dline collision technique and see when it is going to collide and then change its direction, but I don't want that, because the ball can also collide with some moving objects that I cannot predict where they will be just to see if they would collide the ball.

I need some kind of CollideEvent that I would only need to program the cause of a collision. And then I only have to send the ball in a direction and every time it collides with something, the event is going to be executed, and the ball changes direction and that continues forever.

Is there something like that in the engine? Or if someone has another solution, I would appreciate it.

I hope that I was clear enough. It sounds a bit confusing I think.
Thanks a lot. And congratulations for this excellent 3d engine. Awesome.

Re: collision response

Posted: Thu Mar 25, 2004 12:06 pm
by schick
Liamx wrote: I need some kind of CollideEvent that I would only need to program the cause of a collision. And then I only have to send the ball in a direction and every time it collides with something, the event is going to be executed, and the ball changes direction and that continues forever.
Awesome.

I havent read the whole thread but i think irr::scene::ISceneNodeAnimatorCollisionResponse and irr::scene::IMetaTriangleSelector should handle that. Add a collision response animator to the scenenode which is able to collide and add all triangle selectors to a metatriangelselector.

Re: collision response

Posted: Thu Mar 25, 2004 6:59 pm
by Liamx
schick wrote: I havent read the whole thread but i think irr::scene::ISceneNodeAnimatorCollisionResponse and irr::scene::IMetaTriangleSelector should handle that. Add a collision response animator to the scenenode which is able to collide and add all triangle selectors to a metatriangelselector.
Ok, but that animator manages collision automaticaly. I mean, for example when the node collides with something it stops.
But what I want is to program what to do when it collides, something like an event. I don't want to see in each frame if each node is colliding something, I just want to be notified when a collision occurs.

i see...

Posted: Thu Mar 25, 2004 9:25 pm
by schick
maybe have a look at http://irrlicht.sourceforge.net/phpBB2/ ... php?t=1848

Its a very important topic, but my clock just tells me its 10.30 pm and so i got to leave home and have some fun.

Ill find some time in school tomorrow. May i have an idea about something with a good (=easy) design.
First we have a collision response animator (add an animator thats it) and 2nd we need someting event based... more tomorrow

Posted: Fri Mar 26, 2004 5:46 pm
by thesmileman
Yes the link Schick has provided helped me a great deal in my project. I think I might post the code sometime to help other people understand how to do it all.