how to detect collision ?

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
roterl
Posts: 6
Joined: Mon Jun 11, 2007 9:48 pm

how to detect collision ?

Post by roterl »

I have flying object (the player's airplane) over a terrain, and some other object (the enemies).
I have two question:

1) How do I know if the airplane collide the ground? I use the createTerrainTriangleSelector and the airplane indeed don't pass through the terrain. But how can I know that a collision happened ? (so the airplane will be crash for example...)

2) How do I check collision of the airplane with the other objects (there are many object(? Do I have to do an aabbox3d.intersectsWithBox for every object, or is there any better optimized way to do it?

thanks,
Rotem.
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

i don't know much about this my self but i'v found a few links:
http://irrlicht.sourceforge.net/phpBB2/ ... highlight=

http://irrlicht.sourceforge.net/phpBB2/ ... highlight=

http://irrlicht.sourceforge.net/phpBB2/ ... highlight=

It's not a bright future though, most of them suggests some kind of physics
roterl
Posts: 6
Joined: Mon Jun 11, 2007 9:48 pm

Post by roterl »

thanks for your answer,
but before I post this I searched the forums, and saw these posts.

This doesn't answer my questions (or at least I don't understand how to do it)

Rotem.
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

what the posts say, is that you need to do some raycasting. In 3d space that can be rather complicated. I asume that you plane can fly in every direction and that it can roll and climp and such?
I have never done this but i guess you could select some points on the plane that are likely to collide (the tip, the tale and the wingtips) and from them cast rays in all directions. Fx from the tip you could cast a ray forward, one down, one up, one left and one right. But you would need to do this all the time, and it could affect the performance.

But as I said, I have never done this, and I don't even know how to cast a ray.

Good luck!
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

1) perhaps the isFalling() method of ISceneNodeAnimatorCollisionResponse (returned by createCollisionResponseAnimator)? so if isFalling() is false it must have hit the ground.

2) well, I'd probably use the box intersection. Try it and see if it's fast enough.
roterl
Posts: 6
Joined: Mon Jun 11, 2007 9:48 pm

thanks

Post by roterl »

I think the ray tracing will have performances issues, and also that have the possible "pass through" bugs, eg. if I use one on the center and one on each wing edge, that hits between will not be detected. and if putting one mor ray on between, then again hit will not be detected between them two...

right now the code is:

Code: Select all

airplane = smgr->addAnimatedMeshSceneNode(smgr->getMesh(....
terrain = smgr->addTerrainSceneNode(....
.....

	// create triangle selector for the terrain	
	scene::ITriangleSelector* selector = smgr->createTerrainTriangleSelector(terrain, 0);
	terrain->setTriangleSelector(selector);
	selector->drop();
	
	// create collision response animator and attach it to the airplane
	core::aabbox3d<f32> box = airplane->getBoundingBox();
	core::vector3df radius = box.MaxEdge - box.getCenter();
	scene::ISceneNodeAnimatorCollisionResponse* anim = smgr->createCollisionResponseAnimator(
		selector, airplane, radius,
		core::vector3df(0,0,0), 
		core::vector3df(0,0,0),1);
	airplane->addAnimator(anim);
	anim->drop();
	
This prevent hit with the ground, but I dont know how to know when the hit happened.
The enemies will be something like the airplane.

I think I'll try to look at the source of the "createCollisionResponseAnimator" and impelement something similar, that instead of prevent the move through the object, will raise an event.

If you have any better ways, I'll glad to know.
thanks,

Rotem.
Post Reply