1
votes

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?

3

3 Answers

0
votes

So I think there are two ways to do this (didn't test it though):

First is with sensors. If you add a sensor to your 'frozen' static body, the sensor should still detect collisions with other static objects, even though the body itself is static.

The second possibility is having your 'frozen' body be a kinematic shape instead of a static shape. They should still detect collisions, and have the advantage of being able to have a user-set velocity while not reacting from other physics object. However, I'm not totally sure if kinematic shapes generate contact points with static bodies.

0
votes

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
}
-1
votes

IIUC, you could think the exploding ball as having a bigger radius (equivalent to the area affected by the explosion), then the affected sorrounding balls will be those that intersect that bigger circular area.