Computer Science Canada Collision Detection |
Author: | Mr. T [ Sat Sep 24, 2005 3:03 pm ] | ||
Post subject: | Collision Detection | ||
Given the following code, can you show me how to do collision detection with the 1) whatdotcolour method 2) regular method. And can you explain why the ball looks so jittery.
|
Author: | Cervantes [ Sat Sep 24, 2005 6:03 pm ] | ||||
Post subject: | |||||
1) Don't go there. There are two reasons I say this. First, it's complicated for this sort of thing. Ideally, you would check a grid of pixels in front of each ball with a width equal to that of the ball and a depth equal to the speed (vector addition of x and y components of velocity) of the ball. This is complicated by the fact that the ball can be moving in 24 different directions. 2) Use the distance formula.
(This is assuming you are checking for collisions between different, not with that blue square you've got in the middle (?) ) On that note, the blue box drawing method should be outside the for loop. There's no point in drawing a box multiple times. (Yes, your for loop only executes once, but that can be changed easily enough.) Lastly, it doesn't look jittery to me. It actually runs very fast, as there is no delay. If you are looking to do collisions with the box, use some if statements.
|
Author: | Mr. T [ Sat Sep 24, 2005 6:10 pm ] |
Post subject: | Alex's Opinion |
Cervantes wrote: (This is assuming you are checking for collisions between different, not with that blue square you've got in the middle (?) )
leave something out ![]() |
Author: | Cervantes [ Sat Sep 24, 2005 6:17 pm ] |
Post subject: | |
Oh my gosh! Thank you for catching that! +allmybits |
Author: | Mr. T [ Sat Sep 24, 2005 6:24 pm ] |
Post subject: | Alex's Opinion |
![]() |
Author: | Cervantes [ Sat Sep 24, 2005 6:39 pm ] |
Post subject: | |
Between different balls. Hence the circular collision detection approach. |
Author: | Mr. T [ Sat Sep 24, 2005 6:46 pm ] | ||||
Post subject: | Alex's Opinion | ||||
for this method can you break down what each part represents
for this method, do i havta break up each part into its own if statement? because each side of the box represents a different collision outcome.
|
Author: | Cervantes [ Sat Sep 24, 2005 7:02 pm ] |
Post subject: | |
1) If the distance between the centre's of two balls is less than the sum of their radii, a collision occurs. 2) Sort of. You need to split up the x and the y conditions. Hitting the box from the left or right both result in reversing the x velocity. (vx *= -1) Same goes for hitting the box from the top or bottom. |
Author: | Mr. T [ Sat Sep 24, 2005 7:22 pm ] | ||||
Post subject: | Alex's Opinion | ||||
but if i break it up like this
it covers x = 300 on the entire y axis ![]() [EDIT] ok, i figured out. you just add restrictions to the what y should equal
|
Author: | Cervantes [ Sat Sep 24, 2005 7:49 pm ] | ||||
Post subject: | Re: Alex's Opinion | ||||
Pwned wrote:
Don't use equals. Use >= or <=. Reason being that the ball is moving at 3 pixels/loop iteration. Thus, at one time it's at 298, the next it's at 301, and the condition has never been met, though it should have.
|
Author: | Mr. T [ Sat Sep 24, 2005 7:53 pm ] |
Post subject: | Alex's Opinion |
could you explain what the * is supposed to represent? |
Author: | Mr. T [ Sat Sep 24, 2005 7:57 pm ] |
Post subject: | Alex's Opinion |
Ok, i am now gonna implement wat I have learned here into my jezzball game. I wanna avoid using processes, so do you have any idea how I can make the movement of the balls and the creation of the walls run in unison? |
Author: | Cervantes [ Sat Sep 24, 2005 8:08 pm ] |
Post subject: | |
Put everything on a counter. Or a timer. Really, I don't know how you COULD put these things into processes! dx *= -1 is the same as dx := dx * -1 Just as x += 1 is the same as x := x + 1 |
Author: | Mr. T [ Sat Sep 24, 2005 8:12 pm ] |
Post subject: | Alex's Opinion |
Sorry, maybe I was being unclear. Here is my old version of JezzBall. http://www.compsci.ca/v2/viewtopic.php?t=9749&postdays=0&postorder=asc&start=0 I wanna basically do the same thing, minus the process. |
Author: | Cervantes [ Sun Sep 25, 2005 8:13 am ] | ||
Post subject: | |||
Here's a small example, illustrating how to move and create pseudo-objects simultaneously, without the use of processes.
|
Author: | Mr. T [ Sun Sep 25, 2005 2:32 pm ] |
Post subject: | Alex's Opinion |
Thanks Alot. ![]() |
Author: | Mr. T [ Sun Sep 25, 2005 3:50 pm ] | ||
Post subject: | Alex's Opinion | ||
Can someone explain to me why both my Completed Wall Collision Detection and Incompleted Wall Collision Detection are not working?
|
Author: | [Gandalf] [ Sun Sep 25, 2005 5:56 pm ] | ||
Post subject: | |||
Why did you have all that other stuff? The conditions were never being met. The whole point of having the two seperate if statements is so that you do diferent things for x collision, and for y collision. |
Author: | Mr. T [ Sun Sep 25, 2005 6:05 pm ] |
Post subject: | Alex's Opinion |
[Gandalf] wrote: Why did you have all that other stuff?
What other stuff? ![]() |
Author: | [Gandalf] [ Sun Sep 25, 2005 6:10 pm ] | ||
Post subject: | |||
All of this:
and for the other if statement too. You are basically doing 3 levels of collision detection here. |
Author: | Mr. T [ Sun Sep 25, 2005 6:18 pm ] | ||
Post subject: | Alex's Opinion | ||
Well, what I was trying to do was cover collision for both the horizontal surfaces and vertical surfaces of a box. Here is the original code, in which the collision detection works fine.
|
Author: | Mr. T [ Tue Sep 27, 2005 6:50 pm ] | ||
Post subject: | Alex's Opinion | ||
So can anyone figure out why the collision detection isn't working?
|
Author: | Mr. T [ Sat Oct 01, 2005 9:32 pm ] |
Post subject: | Alex's Opinion |
Any ideas? ![]() |
Author: | Cervantes [ Sat Oct 01, 2005 10:00 pm ] |
Post subject: | |
Are you certain that box_x1, box_x2, etc. are all correct? Should you need an array of coordinates? I haven't run your code, yet. Also, why are you mixing your coordinate comparisons with whatdotcolour detection? Don't do that! The whatdotcolour is probably not working at all because just before you check your whatdotcolours, you cleared the screen (at the end of the loop). I think whatdotcolour checks the back buffer, not the front buffer. |
Author: | Mr. T [ Sat Oct 01, 2005 10:36 pm ] |
Post subject: | Alex's Opinion |
Why would i need an array of coordinates? |
Author: | Cervantes [ Sun Oct 02, 2005 8:02 am ] |
Post subject: | |
Because it looks like you are generating boxes. You wouldn't need an array of coordinates if you just removed the old box whenever you create a new box (which I think you're doing), but if you wanted to keep the old boxes as you generate more, you'd need a (flexible) array. Did you try getting rid of the whatdotcolour / placing the cls elsewhere? |
Author: | Mr. T [ Sun Oct 02, 2005 12:45 pm ] |
Post subject: | Alex's Opinion |
Placing the cls elsewhere did help the collision detection with the uncompleted walls. So I'm guessing that my collision detection with the completed walls must be off since it does not have any affect. |
Author: | Cervantes [ Sun Oct 02, 2005 1:43 pm ] |
Post subject: | |
What are completed/uncompleted walls? If you are referring to your "%Incompleted Wall Collision" or "%Completed wall collision", it should have a major affect on both of them. |
Author: | Mr. T [ Sun Oct 02, 2005 2:30 pm ] | ||
Post subject: | Alex's Opinion | ||
Well it didnt have an affect on the completed wall collision section, so I'm guessing there's something wrong with the actual collision code.
|