开发者

How to remove the bounce off colliding objects in box2d?

I am trying to delete an object in box2d when two objects collide.

When my two objects do collide, one of the object bounces off the other. It does delete the other object, but I want it to make it look like it went through rather than 开发者_运维问答a bounce.

I have my body Def type set to b2_staticBody.


You should set the body's fixture to be a sensor:

fixture->SetSensor(true);

You then create a contact listener (class MyContactListener : public b2ContactListener) that detects collisions in the BeginContact method and checks if one of the colliding objects is of this special kind. A good way of doing that is by using these two methods:

/// Get the user data pointer that was provided in the body definition.
void* GetUserData() const;

/// Set the user data. Use this to store your application specific data.
void SetUserData(void* data);

You need to be a bit familiar with C++ to pull it off.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜