Wednesday, November 30, 2022
HomeGame Development2nd - Fixing obtuse inside nook collisions

# 2nd – Fixing obtuse inside nook collisions

I assume that you really want an answer for collisions typically, which additionally works effectively for inside corners.

When resolving a collision towards one airplane, don’t transfer the circle perpendicular to the airplane. As a substitute, transfer it again alongside its path till it doesn’t collide with the airplane. The gap alongside the trail will probably be

$$d = r sec theta = frac{r}{cos theta},$$

the place $$r$$ is the radius of the circle and $$theta$$ is the angle between the airplane regular and the circle.

Then, discover the part (projection) of the circle’s velocity which is perpendicular to (in the direction of) the airplane, subtract that from the entire velocity (or a bit extra if you need a bounce), and proceed simulating the remaining quantity of the movement within the present timestep (a sliding alongside the airplane).

This can be a easy type of “steady collision detection” — we are able to see this course of as discovering the time at which the collision occurs. (In actual fact, you may want to try this too to determine how a lot remaining time there’s for the second step. You’ll be able to compute it from the space moved again and the speed.)

While you hit the second airplane, you may simply do that once more, however there is a catch: you may find yourself simulating the trajectory as if the ball hit them in succession, and the ball will slide out of the nook barely (as if it had hit a curve and slid round it) in some course. That is virtually the identical as your unique hole, besides it’s in velocity relatively than place, so it is perhaps extra acceptable. If you would like it to be completely stopped, you may want to incorporate a while or distance threshold for “these two successive collisions had been truly on the similar second” and determine that sliding into the second airplane simply stops the ball as an alternative of letting it slide additional.

(Additionally, in case of acute nook angles, do not iterate this extra than two steps, or 3 steps in 3D; it will not make additional progress and you do not need to get caught in an infinite loop.)

In any case, this process will be certain that the circle by no means enters a airplane besides barely, because of floating-point rounding error. You will nonetheless want decision for in case the circle does find yourself in such intersecting circumstances, although.

RELATED ARTICLES