0
\$\begingroup\$

My code is just giving false positives. Every frame it reports an imaginary collision.

Here is my code

Sweep And Prune:

 public static void updateObjects() {

     List<BoundingBox> activeList = new LinkedList<>();
     boolean adding = true;
     for (BoundingBox box : axisList) {
        box.getOverlappingPairs().clear();
        if(adding) {
            activeList.add(box);
            adding = false;
        }else {
            for(BoundingBox e : activeList) {
                if(box.collides(e)) {
                    box.setOverlappingPairs(e);
                    System.out.println("COLLISION " + box + " : " + e);
                }else {
                    activeList.remove(box);
                }

Edit:

My AABB boxes are colliding with themselves. I have debugged my classes and have narrowed it down to the sweep and prune class.

I would appreciate if someone would help me.

\$\endgroup\$
  • \$\begingroup\$ What is the imaginary collision between: AABB vs AABB, AABB vs sphere or sphere vs sphere? And just one imaginary collision or several? \$\endgroup\$ – Richard Tingle Mar 26 '18 at 7:05
  • \$\begingroup\$ How about you step through the code till you see where the problem is coming in? Do you know how to step through code one instruction at a time? \$\endgroup\$ – Engineer Mar 26 '18 at 8:26
  • \$\begingroup\$ @ArcaneEngineer i don't know how to step through the code \$\endgroup\$ – Macky ben Jonah Mar 26 '18 at 16:42
  • 1
    \$\begingroup\$ I don't know what IDE you are writing your code in, but for Java, both Netbeans and Eclipse allow you to do that, as does Android Studio. You need to learn how to see where your code is going wrong. \$\endgroup\$ – Engineer Mar 26 '18 at 16:45
1
\$\begingroup\$

I don't know what IDE you are writing your code in, but for Java, both Netbeans and Eclipse allow you to step through code, as does Android Studio. You need to learn how to see where your code is going wrong. Then you can fix this, and many other things, besides, without having to ask others.

Having said this, you need to study (this version of) the algorithm to understand what it's supposed to do. Only in this way can you fix it to do what it should do. I offer this as an answer as it is unlikely that others are going to try all your code; and without trying it, I doubt anyone will see the fault.

\$\endgroup\$
  • \$\begingroup\$ I edited my post. \$\endgroup\$ – Macky ben Jonah Mar 27 '18 at 16:59

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.