View previous topic - View next topic |
Author |
Message |
Barok Stephen Hawking
Joined: 26 Nov 2002 Posts: 248 Location: Bushland of Canada
|
Posted: Mon Sep 20, 2004 6:04 pm Post subject: bounding boxes, npc's and stuff |
[quote] |
|
Hi there! I guess it's been a while since i've been around...
Can someoen point me to tutorial on bounding boxes? It doesn't have to be language specific either... I can probably understand whatever it's written in. I've attempted to create bounding box collision detection and i've had mixed success... It works for collision with map collision tiles, but when i attempt to make bounding box collision detection for npc to npc collisions, they just stand there. (obviously it is registering false collisions.
Anyways, all i need is to be directed to a tutorial. Something to set me straight. ;) _________________ Adosorken: I always liked slutty 10th graders...
Rhiannon: *Slap!*
|
|
Back to top |
|
|
biggerUniverse Mage
Joined: 18 Nov 2003 Posts: 326 Location: A small, b/g planet in the unfashionable arm of the galaxy
|
Posted: Mon Sep 20, 2004 8:47 pm Post subject: |
[quote] |
|
Well, I would first say: if(collidedWith != me){ //real collision } _________________ We are on the outer reaches of someone else's universe.
|
|
Back to top |
|
|
Adam Mage
Joined: 30 Dec 2002 Posts: 416 Location: Australia
|
Posted: Tue Sep 21, 2004 7:57 am Post subject: |
[quote] |
|
This is the half-arsed way i do it, I'm assuming nice 2d square boxes here
Code: | A-------B
| |
| |
C-------D W-----X
| |
Y-----Z
if (A.X>W.X && A.X<Z.X)
if (A.Y>W.Y && A.Y<Z.Y)
collision = true;
|
Basically you have to redo that substituteing B,C and D for A.
And if your boxes move too fast they might fly thru each other. To fix that you could move one pixel at a time and check.
You could also check if the line AB or CD cuts WY or XZ and then check with the vertical lines against the horizontal. That's easier to do if your boxes are always square. _________________ https://numbatlogic.com
|
|
Back to top |
|
|
Bjorn Demon Hunter
Joined: 29 May 2002 Posts: 1425 Location: Germany
|
Posted: Tue Sep 21, 2004 12:42 pm Post subject: |
[quote] |
|
Actually wouldn't the following already be a complete solution?
Code: | A--------
| |
| |
--------B C------
| |
------D
collision = (D.X > A.X) && (C.X < B.X) && (A.Y < D.Y) && (B.Y > C.Y);
|
Note that for each comparison, if it would be false, there can't be a collision between the two rectangles.
|
|
Back to top |
|
|
Adam Mage
Joined: 30 Dec 2002 Posts: 416 Location: Australia
|
Posted: Tue Sep 21, 2004 1:36 pm Post subject: |
[quote] |
|
Quote: | Actually wouldn't the following already be a complete solution? |
Well, if you want to do it elegantly i suppose that would do. _________________ https://numbatlogic.com
|
|
Back to top |
|
|
Barok Stephen Hawking
Joined: 26 Nov 2002 Posts: 248 Location: Bushland of Canada
|
Posted: Fri Oct 08, 2004 3:28 am Post subject: |
[quote] |
|
Just wanted to note that i solved the problem.... It turned out that when i checked npc's for collision with other npc's, i was also checking that same npc as well, hence there would always be at least one npc registering a hit. ;) _________________ Adosorken: I always liked slutty 10th graders...
Rhiannon: *Slap!*
|
|
Back to top |
|
|
janus Mage
Joined: 29 Jun 2002 Posts: 464 Location: Issaquah, WA
|
Posted: Fri Oct 08, 2004 4:02 am Post subject: |
[quote] |
|
Barok wrote: | Just wanted to note that i solved the problem.... It turned out that when i checked npc's for collision with other npc's, i was also checking that same npc as well, hence there would always be at least one npc registering a hit. ;) |
biggerUniverse wrote: | Well, I would first say: if(collidedWith != me){ //real collision } |
|
|
Back to top |
|
|
Adam Mage
Joined: 30 Dec 2002 Posts: 416 Location: Australia
|
Posted: Fri Oct 08, 2004 6:55 am Post subject: |
[quote] |
|
And i thought biggeruniverse was just being a twit. He is truly a wize man. _________________ https://numbatlogic.com
|
|
Back to top |
|
|
biggerUniverse Mage
Joined: 18 Nov 2003 Posts: 326 Location: A small, b/g planet in the unfashionable arm of the galaxy
|
Posted: Fri Oct 08, 2004 4:40 pm Post subject: |
[quote] |
|
adam wrote: | He is truly a wize man. |
That's a stretch. _________________ We are on the outer reaches of someone else's universe.
|
|
Back to top |
|
|
bay Wandering Minstrel
Joined: 17 Mar 2004 Posts: 138 Location: new jersey, usa
|
Posted: Sat Oct 09, 2004 9:01 am Post subject: |
[quote] |
|
janus wrote: | Barok wrote: | Just wanted to note that i solved the problem.... It turned out that when i checked npc's for collision with other npc's, i was also checking that same npc as well, hence there would always be at least one npc registering a hit. ;) |
biggerUniverse wrote: | Well, I would first say: if(collidedWith != me){ //real collision } |
|
http://en.wikipedia.org/wiki/Occam's_Razor
.02$
|
|
Back to top |
|
|
Barok Stephen Hawking
Joined: 26 Nov 2002 Posts: 248 Location: Bushland of Canada
|
Posted: Wed Oct 13, 2004 6:55 am Post subject: |
[quote] |
|
pffff!!!! Don't spoil my moment of triumph! ;) _________________ Adosorken: I always liked slutty 10th graders...
Rhiannon: *Slap!*
|
|
Back to top |
|
|