Working on collisions

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Culando
Posts: 12
Joined: Mon Jan 29, 2007 3:20 am

Working on collisions

Post by Culando »

I think this would still be considered a beginner's question.

My game is progressing and I'm ready to move on to collision detection so the player can take damage and bullets can pop enemies. I found some code in the API, but it's not working like I had hoped.

node (aka boxy) is a player controlled IAnimatedMeshSceneNode that exists in front of the camera.

borka is an enemy IAnimatedMeshSceneNode with an ISceneNodeAnimator that sends it across the screen.

What is supposed to happen - When the player and enemy touch, the player switches to a red colored texture.

Code: Select all

		const core::aabbox3d<f32> boxy_coll = node->getBoundingBox();
		const core::aabbox3d<f32> borka_coll = borka->getBoundingBox();

		if(boxy_coll.intersectsWithBox(borka_coll)){
			node->setMaterialTexture( 0, driver->getTexture("../../media/boxyred.tga") );
		}else{
			node->setMaterialTexture( 0, driver->getTexture("../../media/boxy.tga") );
		}
Basically it works, as in it reads a collision. Problem is, it -constantly- reads the collision. I'm sure that it is (as usual) an obvious solution. Could someone help me out?
greetzyl
Posts: 7
Joined: Tue Mar 13, 2007 2:53 am

Re: Working on collisions

Post by greetzyl »

dearfriend:
If I correctly undersdand what's your problem,I think the mothd like this:
every note heve a pos,or static,or dynamic(but in this instance are dynamic notes) ,So now wo could make a Selector to estimate if the between of pos is approached,thereout ,touch off the events what you want!
I am a students of china !weicame to china!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

There are ways to avoid doing collision detection when you don't need to. If you only have two objects then it is not really a problem to continually do collision testing. If you have a few hundred nodes it may become a problem.

A simple thing that you can do is create a proximity system. The system divides your world up into a quad tree or an oct tree. Each of the children partially overlaps with its siblings. As nodes move around your world, they move between proximity boxes in the tree. When it comes time to do collision testing, you only need to test collisoins between nodes that are in the same proximity box.

You can also divide your collidable objects into static and dynamic ones, maintaining two seperate lists. None of the static objects need to do collision testing against other static objects. You only need to test dynamic objects against other dynamic objects and static objects.

You can also use bounding spheres to further reduce the expense of collision detection. You do simple bounding sphere collision testing before you go further to do bounding box and triangle intersection tests. If you use animated meshes, you could make the bounding sphere big enough to enclose the mesh regardless of its animation state. That way you don't have to update the bounding sphere every time the mesh animates. If the sphere collision test detects an intersection, you can do a bounding box test. If that succeeds, then you do further, more precise collision detection if necessary...

Travis
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I read a paper a while back (sorry, I can't find the link) that suggested referencing your objects in a list sorted by position (e.g. X position). That way you only have to check each object against nearby objects in the list. If you have motile and immotile objects, you could hold them in two lists, although a single list with an if(object->motile) checkCollisions(); might suffice.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Riki
Posts: 30
Joined: Tue Feb 27, 2007 9:12 pm
Location: Croatia

Post by Riki »

I think what culando is asking is not how it could be done but simply (as most other guys starting with collisions) is there a callback that could be setup for invocation upon coll detect. :lol:
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Oh, I've just realised what he's saying. The collision check is always true. Amazingly, the method comment describes both the problem and the solution:
//! Returns the axis aligned, not transformed bounding box of this node.
//! This means that if this node is a animated 3d character, moving in a room,
//! the bounding box will always be around the origin. To get the box in
//! real world coordinates, just transform it with the matrix you receive with
//! getAbsoluteTransformation() or simply use getTransformedBoundingBox(),
//! which does the same.
virtual const core::aabbox3d<f32>& getBoundingBox() const = 0;
Clear enough? ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Culando
Posts: 12
Joined: Mon Jan 29, 2007 3:20 am

Post by Culando »

It always has to be something simple I over look. Every *headdesk* last *headdesk* time! *headdesk*

But at least I have the extremely helpful forum with people to get me those simple things out in the open. :) Many thanks. It works perfect. Next step is to try to get the bullets and the enemies to collide.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

Culando wrote: But at least I have the extremely helpful forum with people to get me those simple things out in the open.
if anything it's the reason why you haven't learned to check the documentation thoroughly.

I have this problem myself sometimes that link is so handy and the post button so easy to press I get lazy sometimes. :P

you don't think I have nearly 1300 posts for nothing do ya? haha
Post Reply