0

So I'm doing a 3D implementation of collision detection.

Considering

  1. Boxes are oriented on the axis.
  2. They are rotatable but has to be orientated on the axis.
  3. Box A and Box B cannot go through each other. However; one of there sides can have similar (x,y,z) points.

Here is a visual aid of what SHOULD happen.

COLLIDING(Examples in RED BOX) ------------------- NOT COLLIDING(Examples in GREEN BOX)

However, example 1 and Example 3 in the GREEN box are considered as collision when I don't want them to be. I want them to be considered not colliding.

Here is my code so far.

if((xMax1>=xMin2)||(xMin1<=xMin2)){
 if((yMax1>=yMin2)||(yMin1<=yMin2)){
 if((zMax1>=zMin2)||(zMin1<=zMin2)){
 isSeperate = false;
 }
 }
 }

What is a conditional that I should add to the code for my issue to be solved.

Jan Doggen
1,1414 gold badges16 silver badges22 bronze badges
asked Jul 10, 2015 at 12:47
0

2 Answers 2

1

It looks like you don't want >= and <=, because then touching boxes are considered colliding. Use > and < instead.

answered Jul 10, 2015 at 14:35
2
  • But then again, Will this let my first and third GREEN box examples to work? Commented Jul 10, 2015 at 14:37
  • @AMDee: you can easily try. The first thing I'd do would be to encode the five cases displayed as test cases, to constantly check my code against. Get (more) comfortable with a testing framework, e.g. JUnit. Commented Jul 10, 2015 at 15:19
0

There are so many different cases to consider when developing collision detection that it can get confusing. I'd recommend implementing the Separating Axis Theorem(SAT) to detect collisions between convex objects. It takes into account position and rotation of objects and lets you handle the collisions. You can take a look at this video I made a few months ago of my implementation of it in C# for 2D shapes: https://youtu.be/VOBSijUuBgc

This will also work for 3D shapes it just needs to take into account the z-axis.

answered Jul 10, 2015 at 13:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.