Collision detection not responding

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
WromthraX
Posts: 16
Joined: Fri Feb 13, 2004 2:53 pm

Collision detection not responding

Post 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.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music."
Kristian Wilson, Nintendo, Inc, 1989.
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post 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!
VeneX
Posts: 228
Joined: Sun Nov 30, 2003 3:32 pm
Location: The Netherlands
Contact:

Post 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.
Visit my website @ www.venex.be
Plethora project will be added to the site
AMD AthlonXP 2600+, 512MB DDR, Radeon M10 (mobile 9600) PRO 64MB, WinXP
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post 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.
Guest

Post 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!
WromthraX
Posts: 16
Joined: Fri Feb 13, 2004 2:53 pm

Post by WromthraX »

That was me above :)
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music."
Kristian Wilson, Nintendo, Inc, 1989.
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

I really hope it helps
Cal'Mihe
Posts: 3
Joined: Thu Feb 26, 2004 11:38 pm

Post 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
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Glad to hear it Cal'Mihe.
ZDeveloper
Posts: 35
Joined: Wed Mar 24, 2004 2:34 pm
Location: Germany
Contact:

Post 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.
Last edited by ZDeveloper on Wed Mar 31, 2004 9:15 pm, edited 1 time in total.
Look at http://www.z-software.de for interesting games.
Liamx

collision response

Post 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.
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Re: collision response

Post 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.
Liamx

Re: collision response

Post 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.
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

i see...

Post 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
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post 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.
Post Reply