Computer Science Canada help needed! |
Author: | gamer [ Fri Apr 09, 2004 4:02 pm ] | ||
Post subject: | help needed! | ||
hi all here i hav a little program with bouncing two balls plus a square in the middle to "block" the balls questions: 1. if u let the program run for awhile, u'll notice that when the ball hits the square at the corner, the ball does weird things (ex. sliding along the square).......why is this happenin?? how can i fix it? 2. noticing that both balls go at same speed (-2), is it possible if i want to hav one ball go at a random speed? 3. do i just use math.distance for the two bals to bounce off each other?
thnx |
Author: | Paul [ Fri Apr 09, 2004 4:08 pm ] |
Post subject: | |
the reason for that is the ball isn't bouncing off the edge of the square properly, I had the same problem in paddleball. I didn't take a close look at the code but there could be some possiblilities: 1. the code only checks for the most up, left, down right, coordinates of the ball, so when the ball comes towards the square's corner diagonally, it doesn't detect the collision at all. 2. the collision checks for coordinates that are bypassed because of the large increments of the coordinates of the ball. IE: the wall is at 230, the ball checks for 229, doesn't detect anything, the ball moves 5 forward, checks for 234, and misses the wall. I dunno how to fix it, because I haven't learned that complex equation that zylum was going to explain. |
Author: | gamer [ Fri Apr 09, 2004 4:35 pm ] |
Post subject: | |
thnx paul, after i looked at ur 2nd suggestion i tried changing the speed of the ball to 1 instead of 2.... and everythin was fine!! however, remember i had the other problem of wanting one ball to move at random speed (ie: speed of 1 for 2 seconds then speed of 3 for 2 seconds etc)....so would it stil work?? n how? |
Author: | Paul [ Fri Apr 09, 2004 4:41 pm ] | ||
Post subject: | |||
it would be weird? I mean you want it to suddenly speed up while it's bouncing? the you just go like
or are you asking for the ball to bouce off at random angles as it hits the walls? that could be a little more complicated. |
Author: | gamer [ Fri Apr 09, 2004 4:48 pm ] |
Post subject: | |
no no no....like 4get the collision for a sec....what i need is one ball travel at a varying pace/speed so if normally it goes at speed of 1, then one or two sec later it goes faster OR slower......n continues but if talking about collision of the obstacle's corner, i think i must need the speed to be 1.....then maybe i can random the delay? lol but then delay applies for both of the balls, n i need just one ball to be delay, how can i do this?? |
Author: | Paul [ Fri Apr 09, 2004 4:54 pm ] |
Post subject: | |
so one ball travels at a constant speed, the other speed varies. Maybe have a counter inside the loop, and have the 2 balls increase by 2 different variables, when the counter counts that the loop has run say, 10 times, it changes the increase variable from 1 to 3, then after it runs another 10 times, it changes to 2, so just randint inside the loop? I dunno about the delay thing though. It could probably mess up your collision detection too. |
Author: | gamer [ Fri Apr 09, 2004 5:27 pm ] |
Post subject: | |
damn even tho i change the speed to 1 the corner detection would screwup if i let the program run longer.....i guess this isnt the way to fix it wut should i do then? |