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?
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.
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
}
IIUC,你可以认为爆炸球具有更大的半径(相当于受爆炸影响的区域),那么受影响的周边球将是那些与较大圆形区域相交的球。
链接地址: http://www.djcxy.com/p/66162.html上一篇: BulletPhysics“setLinearVelocity”不动
下一篇: 对象不移动时如何检测碰撞?