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\$
4
  • \$\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\$ Commented Mar 26, 2018 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
    Commented Mar 26, 2018 at 8:26
  • \$\begingroup\$ @ArcaneEngineer i don't know how to step through the code \$\endgroup\$ Commented Mar 26, 2018 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
    Commented Mar 26, 2018 at 16:45

1 Answer 1

0
\$\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\$
1
  • \$\begingroup\$ I edited my post. \$\endgroup\$ Commented Mar 27, 2018 at 16:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .