Search code examples
game-physicsjbox2dcollision

How Can I Detect Collisions When Objects Aren't Moving?


I suppose to understand the question, I have to explain the game. Balls are falling down the screen, and when you click on the ball it changes into a different ball based on its type. For example, clicking on one ball will freeze surrounding balls in place for a time. Some will explode and destroy others nearby.

In the event that I have a frozen ball (body.setType(BodyType.STATIC)), and another ball next to it explodes (A kinetic ball then set to a larger static ball), no collisions are detected.

What can I do to detect the collisions of static bodies? I mean, yeah, they aren't moving so they shouldn't collide, but you have a static object and then, the next moment, you have another static object touching it, so shouldn't that count for something?

Let me know if you need more clarification.

UPDATE: I have an idea that might work, but it requires doing something I can't figure out. How can I make a dynamic body behave like a static body? I mean, to have a dynamic body's position unaffected by gravity or collisions?


Solution

  • After some digging around in the API I finally found the method that helps me. Below is the code that fixes the problem.

    //Find the two types of bodies in question
    if (AABB.testOverlap(ballA.getBody().m_fixtureList.m_aabb, ballB.getBody().m_fixtureList.m_aabb))
    {
        //Add new contact to collisionListener
    }