Page 1 of 1

any idea about dynamic collisions???

Posted: Thu May 13, 2004 2:38 pm
by freestyle
i need some code for checking collision bettween the bullets and the player
if u have some please send
it's an urgent problem
please help...

Posted: Fri May 14, 2004 3:54 am
by Domarius
This should be in the beginners forum I think :)

Basically, you need to keep an array of all your active bullets (adding and deleting as nessecary).
You iterate through that array, and compare each bullet's bounding box with the player bounding box. If one overlaps, then a bullet has hit the player.

Posted: Mon May 17, 2004 5:29 am
by freestyle
ok...
but how can i compare bounding boxes?

Posted: Thu May 20, 2004 5:10 am
by Domarius
Easy. Read the help, that's what I did.

Here's a snippit from my code, where I do bounding box collision between the "sydney" model, and the "faerie" model;

Code: Select all

if (sydney->getTransformedBoundingBox().intersectsWithBox(faerie->getTransformedBoundingBox())){
    printf("collision\n");
}
Something that tripped me up at first is; you can't used getBoundingBox, because it only returns the size and position the bounding box was when the model was loaded. You need to use getTransformedBoundingBox, to get the one that actually represents where they really are and their current size.