1
\$\begingroup\$

I have two figures - a circle and a rectangle and i have a method that checks whether the two figures collide. How to prevent them from overlapping during collision?

\$\endgroup\$
  • 1
    \$\begingroup\$ Check whether they are going to collide instead of if they are colliding maybe. \$\endgroup\$ – BitNinja May 23 '14 at 22:40
  • 1
    \$\begingroup\$ If you are able to check if they are colliding/overlapping, you should be able to calculate by how much. If you are doing a reactive collision, then you should shift either the circle or the rectangle away by that calculated amount. \$\endgroup\$ – midasmax May 24 '14 at 0:11
  • 1
    \$\begingroup\$ Very important: is this physically accurate motion, or is it kinematic motion (i.e. controlled purely by player input, without momentum etc.)? -- This impacts on the answer in several ways. \$\endgroup\$ – Engineer May 24 '14 at 10:43
1
\$\begingroup\$

One solution would be to use raycasting collision for the circles, and traditional box-collisions for rect-rect collisions.

\$\endgroup\$
1
\$\begingroup\$

if the speed of the objects is constant (or you can predict it accurately) you can check if they are going to collide, if yes don't move object (or move them so they touch side to side)

one other thing you can do is save previous location, calculate object's new location, if objects collide, move to previous location

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.