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.
how to detect collision ?
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
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
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!
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!
thanks
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:
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.
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();
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.