Collisions can be determined by testing for line intersections. Imagine a line representing the ground and an object above, falling down. At time t1 , take the center point p1 of the object. At time t2 , move the object down and take the center point p2 of the object. If the line formed by endpoints (p1, p2) intersect the ground line, a collision has occurred. On a collision, reset the object to its original position before the movement. When a collision occurs, be sure to reset the object by the same point used to determine the line intersection. In this example, I use the center point, so the object should be reset by the center point, not its actual x, y (usually top left) coordinate. It is not always the case that resetting by the x, y coordinate is sufficient. This can be seen in the following picture. It can be seen that even if the object isn't moving, but its size changes, a line intersection can occur, and resetting the object to its x, y position will...
Comments
Post a Comment