Moritz Schöfl
Moritz Schöfl

Reputation: 763

C++ Box2D, Simulating Dynamic Body behavior with Kinematic Body

Ive got a problem with Box2D.

I´ve coded a game like this Warcraft 3 map.

http://www.youtube.com/watch?v=PKa1CNw6Q5A

Where you control a character and can throw fireballs which can collide with objects.

For the collision between Fireballs and Pillars for example I used kinematic bodies for both (Normally they dont collide, but with a hack i got it working) which works just fine because I just need to track the collision and I cant use dynamic bodies because I dont want them to be pressed apart if they collide (OnTouch behavior is implemented in spell script).

But now I need collision between Pillars and Characters, so basically I want them to behave like rubber balls, when the Character is thrown with velocity x against the pillar it should bounce off. But for this I would need the behavior of a dynamic body, so is there an easy way to simulate the behavior of a dynamic body with kinematic bodies? (maybe overwriting something?)

Ive no clue how Box2D works intern and would be glad if anyone understands my question and can help me.

Upvotes: 3

Views: 882

Answers (2)

FuzzyBunnySlippers
FuzzyBunnySlippers

Reputation: 3397

It sounds like you need to use dynamic bodies for everything, but have more explicit control over how they respond after a collision.

For example, all the "projectile" like things should be sensors or use the group ID or mask bits to make it so they don't physically collide with other objects. Even though there is not a collision response, there is a callback you can create to detect the collision and decide what to do based on it.

Hacking the physics seems like you could destabilize something that works reliably...having done this myself, I appreciate the inclination.

Look at this tutorial and the one immediately after it. They really have great information (and no, they are not mine...dang it).

For some more info on contact filtering, take a look at this other article.

Upvotes: 3

Luca Davanzo
Luca Davanzo

Reputation: 21520

I suggest you to take a look at Chipmunk library!

It's a physic engine (2D), written in C. I've used it in my projects, works very well!

Upvotes: 0

Related Questions