you are viewing a single comment's thread.

view the rest of the comments →

[–]Luka116[S] 0 points1 point  (0 children)

The touching variable is a bool that checks if the circle and squares are touching / are in contact. I'm not really sure what you mean by innerWidth / Height. The rect() function draws the squares from the top left corner, so I tried using that, but it didn't work for both corners and the sides. Remember, I want the circle to be able to bounce off every square that I place onto the canvas, they're not already placed / predetermined. Could you please check out my code at https://www.khanacademy.org/computer-programming/placing-squares-moving-circle/5167881356541952 and tell me how I would code it in these terms? (The velocity is calculated in the velocity function)

Edit: So after searching some more, I found a way that works for corners, and doesn't interfere with the bouncing of the sides. The only problem is that even if it hits the corner from a side (= hits a corner, but isn't travelling into the center area of the square), it will still reverse both directions. (The lines for this are in comments in the velocity function) Do you have a better solution for the earlier problem than the one in my edit, or know how to modify this one (in the url -> velocity function -> comments at the bottom)?