开发者

Box2d sensor rotation problem

开发者 https://www.devze.com 2023-02-15 13:12 出处:网络
in my app the user is able to move or rotate a box2d fixture. The collision detection works fine. But if I set the fixture as a sensor, with the SetSensor(true) method, the collision detection reacts

in my app the user is able to move or rotate a box2d fixture. The collision detection works fine. But if I set the fixture as a sensor, with the SetSensor(true) method, the collision detection reacts weird. In the following picture the red rectangle is the sensor, but a colli开发者_JAVA百科sion is also detected if an other fixture collides with the black border.

Image: http://img851.imageshack.us/img851/7292/rect.png

Is it possible that only the red rectangle reacts as a sensor?

BR


I found the help here: Box2D Forum

I just forgot to check if the contact is touching (with the IsTouching() method)! Now it works fine!!!


b2BodyDef bodyDef;
bodyDef.type = b2_staticBody;
bodyDef.position.Set(position.x/PTM_RATIO, position.y/PTM_RATIO);
bodyDef.userData = NULL;
b2Body *body = _game.world->CreateBody(&bodyDef);

b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(size.x/2/PTM_RATIO, size.y/2/PTM_RATIO);

b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.isSensor = true;

body->CreateFixture(&fixtureDef);
body->SetTransform(body->GetPosition(), rotatingAngle);
0

精彩评论

暂无评论...
验证码 换一张
取 消