문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top