"breakable Compound Bodys"

Post and discuss features you'd like to see in the BEPUphysics library.
Post Reply
DJohnny
Posts: 2
Joined: Mon Aug 04, 2008 3:13 pm

"breakable Compound Bodys"

Post by DJohnny »

Hi,

first I want to congratulate you for this graet physics system.

Here my suggestion:
As far as I see Compound Bodys never fall apart because of a force that "trys to devide them". But whouldn't this be a cool feature? A value that you can put when you connect two bodys together to a compound body, which says, how strong the connection between them is. That way one could design "breakable objects", for example a glas made of 6 parts put together to a whole one, which can braek apart if it falls from a table. :D

Greetings

Michael
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: "breakable Compound Bodys"

Post by Norbo »

This should actually be doable with a little trickiness now; compound bodies are designed in hierarchies partly because of this. Subbodies can be removed at runtime from a parent compound body, forming a newly separate entity.

The tricky part would be deciding on a reason to break. Many FPS games tend to use an arbitrary HP value associated with a game object to determine how much they can get shot before separating into a 'broken' state (many times actually being a totally different set of bodies than those used to construct the original compound, but a breakable compound method is doable using a similar setup). Forces could be monitored on an entity as well, though there aren't any events for that as of yet so the 'force' and 'torque' fields of the compound would need to be checked on a per-frame basis. This would give a fairly good approximation of separating due to large impacts or other forces, though it can't be totally accurate since the compound itself is connected in a completely rigid manner.

I haven't extensively tested some of the features used to create the breakable compound effect though, its possible that problems exist with dividing compounds at runtime in the current version.

Thanks for input!
DJohnny
Posts: 2
Joined: Mon Aug 04, 2008 3:13 pm

Re: "breakable Compound Bodys"

Post by DJohnny »

Hi Norbo,

thanks for you fast answer. I tried what you suggested with a modyfied version of the Compound Bodies Demo (17). I changed the starting position of the long cb3 to a higher one, to 20, so it crashes faster to the ground. :twisted: In the Update function I added something like this:

Code: Select all

            float brechwert = 1000f;
            if (cb3.totalForce.X > brechwert || cb3.totalForce.X < -brechwert || cb3.totalForce.Y > brechwert || cb3.totalForce.Y < -brechwert || cb3.totalForce.Z > brechwert || cb3.totalForce.Z < -  brechwert)
            {
                List<Entity> data = new List<Entity>();
                data = cb3.getBodies();
                cb3.removeBody(data[4]);
            }
When the compound Body crashes to the ground, it is reconised correctly, but the cb doesn't break, but it "flyes away" somewhere at high speed still in one piece. :?

Shouldn't I use removeBody() ?

Greetings

Michael
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: "breakable Compound Bodys"

Post by Norbo »

I'll need to do some testing for myself to see where any errors may be; removeBody should be the thing to use. The problem areas could be in its inertia tensor recalculation, velocity transfer (if I remember correctly, a removed subbody will attempt to maintain the velocity of its former parent when 'exiting'), and graphics. The graphics will definitely show up incorrectly since it won't recalculate the CompoundBody's vertices after it splits, so the removed body will be invisible and the parent will be unchanged graphically. Additionally, a removed body will not automatically exist within the space, it would have to be added to the space individually to be simulated (at which point you can add it to the renderer separately as well).

I'll fiddle around with it a bit.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: "breakable Compound Bodys"

Post by Norbo »

Alrighty, I've managed to get a working setup in the currently in-development version... Unfortunately, there is a problem with the CompoundBody.removeBody method in regards to simulation islands which can cause a crash when you re-add the 'broken' piece back into the space.

This and a few other issues are making me think I should release the first half of v0.7.0 early as v0.6.1.


For reference, here's the whole set of testing code I used:

Code: Select all

            if (keyboardInput.IsKeyDown(Keys.P) && breaker.getBodies().Count == 7)
            {
                entityRenderer.removeEntity(breaker); //Remove the outdated graphic of the compound
                for (int k = 0; k < 3; k++)
                {
                    Entity toRemove = breaker.getBodies()[2];
                    breaker.removeBody(toRemove);
                    
                    space.add(toRemove);//Add the 'broken' entity back into the space
                    entityRenderer.addEntity(toRemove); //Give the entity a graphic
                }
                entityRenderer.addEntity(breaker); //Add an updated graphic for the compound
            }
Where "breaker" was cb3 from the compound bodies demos. I put this in the update method so I could choose to separate the middle three bodies when I hit P.
goldsword
Posts: 18
Joined: Fri Dec 05, 2008 8:46 pm

Re: "breakable Compound Bodys"

Post by goldsword »

Is there anyway to change the shape of a subbody during runtime, for instance say your have a car chassi with 4 wheels and you want to simulate a flat tire, you dont want to remove the wheel just make it smaller causing the compund to wobble. Setting the height of a sub body doesnt seem to do anything...
User avatar
Zukarakox
Not a Site Admin
Posts: 426
Joined: Mon Jul 10, 2006 4:28 am

Re: "breakable Compound Bodys"

Post by Zukarakox »

Im not sure setting the height of something changes anything to begin with, but remove the object from the body, change the height, then re-add it to the body should do it.
i has multiple toes
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: "breakable Compound Bodys"

Post by Norbo »

If you're using the vehicle class, either modifying the suspensionLength or changing the wheel shape entity's dimensions should work. The wheel shape entity itself isn't handled by the space, but instead just used to collide. Changing the fields alone should work in most cases. Note that a box has 6 fields; width, length, height, halfWidth, halfLength, and halfHeight. I'd recommend setting all 6 to the correct values. I'm planning on making some properties to make this more intuitive.

For other things, calling makePhysical or makeNonDynamic on the entity after setting its dimensions should fix any problems with the inertia tensor and such. The demos renderer won't update the entity's graphics until the entity is removed and re-added to the renderer, though.
Post Reply