Computer Science Canada collision help |
Author: | shoobyman [ Wed Nov 08, 2006 9:20 pm ] | ||
Post subject: | collision help | ||
alright. run the program, click somewhere and the ball will move. you will notice that collision is not happening properly with the box in the middle. Anyone have any suggestions as to how i could do that? as you can see i have already tried. |
Author: | DemonZ [ Wed Nov 08, 2006 9:54 pm ] | ||
Post subject: | |||
ok this looks like a tough one, but I might have a solution, your collision is between a box and an oval, this is the problem: you are trying to use a rectangular collision formula for a circle, which I highly doubt will be accurate, and turns out it is as I said, inaccurate. I think the only way you could solve this problem is if instead of using this collision formula :
you should try to look into colliding irregular objects together(there is actually a tutorial for collision in general here:)http://www.compsci.ca/v2/viewtopic.php?t=13661 but, there is another form of collision that comes into mind: whatdotcolor. whatdotcolor is essentially a single dot (or pixel) that checks the current color of the portion of the screen, so what I propose you do is draw a dot and position the dot according to your circle, that way the single pixel will check what color it is on, then make an if statement like so: if whatdotcolor (x, y) = black then % collision end if Now im a little tired so I will post another couple of solutions that come into mind tommorow, hopefully I will be able to think straight. |
Author: | richcash [ Sat Nov 11, 2006 1:41 pm ] | ||
Post subject: | |||
The problem is you need to also make the velx *= -1 (or make the ball bounce off the vertical parts of the box). Here's a temporary solution : Change the collision detection if statement at the bottom to this :
This may look right, but that's because the ball radius is only 5. To make it correct, you have to also check if the distance from the center of the ball to any corner is less than the radius of the ball. When this collision happens, you may want to keep it simple and just have both velocities multiplied by -1. Ask any questions if you don't understand what I did! |