Computer Science Canada [Tutorial] Troubleshooting collision detection |
Author: | jrblast [ Wed Jan 18, 2006 11:14 pm ] | ||||||
Post subject: | [Tutorial] Troubleshooting collision detection | ||||||
Okay, well troubleshooting is very important, and though I have noticed alot of people (mostly at school) couldn't detect colision if their lif depended on it.... But it is much easier to use these methods than it is to try to get someone else to fix it for you, because this way is: A) Faster And B) More educational (Since you notice the problem on your own, always better to do that than get someone else to) Anyways, there are multiple ways to troubleshoot, I'll post em in whichever order I think of em. The first way is, if you are doing collision detection, and your if statement is faulty, but you dont know in what way, just use the drawbox thing Copy the parts of the if statement that have the boundry information into a drawbox procedure, I.E.
then move the parts on the right side of the comparison operators (the =, <, >, etc... signs) into a drawbox thing, remember, the order of locations in the drawbox thing is x1 y1 x2 y2, but the order in the if statement is x1 x2 y1 y2 so you get
(remember, you need to specify a coulour, in this case i chose black) At this point, if you draw that, you will get a square, because if you look at the last part of the drawbox command, is wallY + wallWidth, width is horizontal, but you would want vertical, AKA Height... (this one recently happened to me, took a week before i thought to draw the box the second way would be if you are unsure of a variable, or even a predefined variable like maxx and maxy. If you have a program like this:
As you may have noticed (since this is a simple code) the grid size of the object and user are not the same, one is 10s the other is 5s, so you use a put statement to put the variable values somewhere, then you will hopefuly notice the problem (though, if you use the method of collision detection as used above, this problem will be avoided, however, you will typicaly want to have things aligned when using a grid...I do believe thats the point of a grid. At this point i only have those two methods, however i will post more later if i think of them. I'll look on teh help forums to see if theres anything there "solvable" by trouble shooting, also, you can post em here and I'll try to help you out. |