I need help with collision bounding box - Irrlicht tut only shows me how to use rays to detect bumped scene nodes.
The collision section in this post doesn't solve my problem: http://irrlicht.sourceforge.net/phpBB2/ ... 481#155481
Say,
If a have a spaceship's bullet flying around with lots of rocks, how do I check if the spaceship's bullet collide with ANY rocks, thus doing some actions to the rocks (destroy it and the bullet, etc) - with a bounding box.
Thanks.
[n00b] How to do collision detection with a bounding box??
-
- Posts: 12
- Joined: Sat Dec 27, 2008 1:26 pm
- Contact:
Iterate through each bullet and then each rock and check whether their bounding boxes intersect using the functions of the bounding box class:
Code: Select all
for each bullet
for each rock
if bullet bounding box intersects with rock bounding box
destroy rock (and bullet? if so break out of rock loop and move onto next bullet)
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
I'd use rays for that.
Consider that projectiles move relatively quickly. If you only checked the projectile against each box each frame (either as a point, or as a box-box test) then you run the risk of having it passing right through targets between one frame and the next.
So instead, store the projectile's previous position, and each frame create a ray from its previous position to its current position. Use that ray in your collision check, as per the collision example.
Consider that projectiles move relatively quickly. If you only checked the projectile against each box each frame (either as a point, or as a box-box test) then you run the risk of having it passing right through targets between one frame and the next.
So instead, store the projectile's previous position, and each frame create a ray from its previous position to its current position. Use that ray in your collision check, as per the collision example.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 12
- Joined: Sat Dec 27, 2008 1:26 pm
- Contact:
I've experimented something
I tried doing this but since Bullet is derived from Actor I always got "P5Actor" when doing "std::cout << world->actors; << "\n" ".
I tried doing this but since Bullet is derived from Actor I always got "P5Actor" when doing "std::cout << world->actors; << "\n" ".
Code: Select all
core::array<Actor*> collide(f32 frameDeltaTime)
{
core::array<Actor*>collided;
for(s32 i=0;i<(world->actors.size());i++)
{
Actor* c = world->actors[i];
if (typeid(c) != typeid(this))
if (this->node->getTransformedBoundingBox().intersectsWithBox(
world->actors[i]->node->getTransformedBoundingBox()))
{
collided.push_back(c);
//std::cout << world->actors[i]; << "\n";
}
}
return collided;
}
-
- Posts: 12
- Joined: Sat Dec 27, 2008 1:26 pm
- Contact:
It depends on the size and speed of both objects. If an object is very small and fast (i.e., it can travel further in one 'tick' than length of its bounding box in that direction), then you should not use a simple bounding box test.Raden Mu'az wrote:How about the spaceship colliding with a rock? Does this also need a ray for coll. detection?
Travis