I have been trying to figure out how to accurately collide different shaped objects with a circle, and I finally finished. Now I am trying to figure out how to add the gravity and collision response so that this will be useful for a game.
Use the arrow keys to move the circle. If you touch the circle to an object, the object will fade out by 50%.
Each shape is in 40x40px cell, so first I checked if the circle is touching any cells. If the circle is touching the cell, then I checked to see if the circle is touching the shape in the cell.
I did all of this with common circle-circle and circle-rectangle collision detection methods, except for the triangles.
So, let me see if i got it right. You first check is the "cells" are touching (using hitTest, i assume?), if they are, you then check if the ACTUAL shapes in the cell are touching (perhaps by position?).
No. I don't use hitTest because it is only useful for two rectangles, and I am using a circle. You have to detect the collision using math instead.
I don't really have time to explain right now, but I can try to make a tutorial within the next week. I haven't found any really good tutorials for circle-square collision, but you can definitely find some for circle-circle.
oh, a tutorial would really be helpful, i'll be looking forward to it (if you ever do it). Guess for now i'll stick to collision boxes. Thanks for the advice.
Yeah, I can find the point of collision, but my knowledge of physics is limited. I am not completely sure how to use the forces to find how to ball would react.
Well you have positions, speed of ball, point of collision. With that you can get vector from center of mass(for ball it is it's center too) to collision point and that will be axis of collision. Project ball speed as a vector on this axis(vector too) and you will get how much energy of a ball is distributed along collision axis. Now you can subtract it 2 times to reverse this energy as if it fully reflected from surface it collided with
I did all of this with common circle-circle and circle-rectangle collision detection methods, except for the triangles.
I don't really have time to explain right now, but I can try to make a tutorial within the next week. I haven't found any really good tutorials for circle-square collision, but you can definitely find some for circle-circle.
Good luck with you future endeavors. ^^