Game Programming and Development Tools

Pre-Action Collision detection problems. – Mene-Mene

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
(^ Don't I sound smart?) Ok, I'm re-writing the collision detection function for "The Well of Bethlehem", and have run into the biggest brain teaser of my career (1 yr in March!) I'm trying to write a function which will take the x/y/endofimagex/endofimagey coordinates (This is all in a graph, and so odd shapes aren't there thankfully) between 2 images, and will take the direction of which the player is going, and the distance travelled, and calculating what will happen to the coordinates after the player has moved. I can do it if all the images were the same size, but their not, and so I need to create a ><= formula which will account for 4 directions. The hard part is getting your head to think, IF I'm here, and this and this is true is this a collision without something physically there. I don't know if (You BB guys this is your big part) drawing to the BackBuffer will do an invisible collision. Image collision will cause too much of a flicker, seeing as the images will overlap, then come back to see that the player can't make that move. Here's my existing code:

Sorry for the no tabs, this ugly thing doesn't support my beautiful spacing. Although I Haven't really done any commenting, I hope its somewhat self-explanitory.


Function PossHit(subjectx,subjecty,subjectendx,subjectendy,subject2x,subject2y,subject2endx,subject2endy,direction,range)

If direction = 1

If subjectx < (subject2endx + range) And subjectendx > subject2x

If subjecty = subject2y And subjectendy = subject2endy

Return True

Else

Return False

EndIf

Else

Return False

EndIf

ElseIf direction = 2

If subjecty =< (subject2endy + range) And subjectendy => subject2y

If subjectendx => subject2x And subjectx =< subject2endx

Return True

Else

Return False

EndIf

Else

Return False

EndIf

ElseIf direction = 3


If subjectendx < (subject2x - range) And subjectx > subject2endx

If subjecty = subject2y And subjectendy = subject2endy

Return True

Else

Return False

EndIf

Else

Return False

EndIf


ElseIf direction = 4

If subjectendy > (subject2y - range) And subjecty < subject2endy

If subjectx = subject2x And subjectendx = subject2endx

Return True

Else

Return False

EndIf

Else

Return False

EndIf

EndIf


End Function

Any help will be appreciated.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

[This message has been edited by Mene-Mene (edited November 22, 2006).]

fearless

Member

Posts: 91
From: Romania, Tg Mures
Registered: 11-26-2005
quote:
Originally posted by Mene-Mene:
The hard part is getting your head to think, IF I'm here, and this and this is true is this a collision without something physically there. I don't know if (You BB guys this is your big part) drawing to the BackBuffer will do an invisible collision. Image collision will cause too much of a flicker, seeing as the images will overlap, then come back to see that the player can't make that move

Just from the top of my head.
Try using a second Collision Detection Box. It should be larger than your existing one. If the intruder touches the large CD Box of the intruded, he will stop. This should stop image overlapping without having to think ahead.

------------------
My projects page

'As there are plants which will flourish only in mountain soil, so it appears that Mercy will flower only when it grows in the crannies of the rock of Justice; transplanted to the marshlands of mere Humanitarianism, it becomes a man-eating weed, all the more dangerous because it is still called by the same name as the mountain variety.'
The Humanitarian Theory of Punishment
by C. S. Lewis

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
If this only had one setup, that would be the logical thing to do, unfortunetly, I'm planning on haveing 20 lvls.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

fearless

Member

Posts: 91
From: Romania, Tg Mures
Registered: 11-26-2005

//this is if Y is 0 at the top of the screen

int subject1CDx = subjectx -5;
int subject1CDy = subjecty -5;

int subject1CDendx = subjectendx + 5;
int subject1CDendy = subjectendy + 5;


Function PossHit(subject1CDx,subject1CDy,subject1CDendx,subject1CDendy,subject2x,subject2y,subject2endx,subject2endy,direction,range)

[This message has been edited by fearless (edited November 22, 2006).]

D-SIPL

Moderator

Posts: 1345
From: Maesteg, Wales
Registered: 07-21-2001
For my engine I have used tiered collision detection, so basicly using the same concept as LOD. When the first box has collided then we check for second and the third is ultra detailed. It's a simple concept and works really well.

------------------
"One World. One Web. One Program." -Microsoft promotional advertisement
"Ein Volk, ein Reich, ein Fuhrer!" -Adolf Hitler
"I believe in freedom... not freedom like America, freedom like a shopping cart"