Strange behaviour after calling a method

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Nostromo
Posts: 4
Joined: Fri Feb 26, 2010 3:45 pm

Strange behaviour after calling a method

Post by Nostromo »

Hi everyone!

Every thing up untill now is working as should, I think.... My little cubes drop on the ground and do their physics thing and all.
But when I run the next method Bepu starts to act crazy, the shockwave works but after that.... My little cubes start to jump around with almost no end, new physics box entities drop almost all trough the floor and other wacky things happen.

Code: Select all

 public void ApplyShockToAllEntities(Vector3 shockWaveOrigen, float force, float forceDistance)
        {
            float distance;
            foreach (Entity e in space.entities)
            {
                distance = Vector3.Distance(shockWaveOrigen, e.worldTransform.Translation);
                if (distance < forceDistance)
                {
                    e.linearVelocity -= Vector3.Normalize(shockWaveOrigen - e.worldTransform.Translation) *(force   *  (forceDistance / distance) );
                }
            }
        }
I call that method like this:

Code: Select all

   if (input.GamePadState.Buttons.B == ButtonState.Pressed && input.OldGamePadState.Buttons.B == ButtonState.Released)
                physicsManager.ApplyShockToAllEntities(player.Position, 25, 125);
Cant seem to find out whats wrong..... I need a experts help...

Thanks
Greets and sorry for my shitty english,
Nostromo
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Strange behaviour after calling a method

Post by Norbo »

This is most likely an excessive geometry size issue. Floating point numbers have limited precision, and the general case collision detection system is a little sensitive to the errors. By 'normalizing' the involved entity sizes down to a safe range like .5 to 10 units, these problems should disappear.

For more information (for later readers that search up this post), you can check this other thread for more information: http://www.bepu-games.com/forums/viewto ... ?f=4&t=841

And your english is actually quite good :wink:
Nostromo
Posts: 4
Joined: Fri Feb 26, 2010 3:45 pm

Re: Strange behaviour after calling a method

Post by Nostromo »

Thanks for your reply, and for the reply on my other topic.

Well my boxes are of the correct size....

The boxes I throw in my space are of the size 1.0f x 1.0f x 1.0f for the smaller ones. and 4.0f x 4.0f x 4.0f for the bigger boxes. Every thing works properly, all the boxes that I put in do their physics correct.
but after I do my method it all goes wack.

if I put in new boxes they fail when I have ran the method before they where created....

Hard to explain.... behold the almighty power of youtube: http://www.youtube.com/user/nostrononom ... QKvc9AZiHw

Here you see that every thing works correctly at first... I create the small boxes just above my player model (Its not so clear in the movie but look hard :) ). then I create the bigger boxes, wich also goes correctly.... As long as I dont run the method everything keeps working correctly, except framerate ifI create to much entities but that is normal behaviour.

Then I press my button twice to execute the method, at second 11 and 12 of the movie. after these two shock waves it fails... :( You see that almost all of the new smaller boxes I create drop throug the level, and the bigger ones I create at the end are jumping like bunnies on steroids.

Any clues where to look for a fix?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Strange behaviour after calling a method

Post by Norbo »

It looks like whats happening is the static triangles of the StaticTriangleGroup are having their velocities changed by the explosion. Collisions with them will take those velocities into account; since the triangles were exploded downwards in general, the boxes had a low penetrating velocity (or even a separating velocity) and the collision solver acted accordingly. v0.12.0 is slated to include some changes that would make it much harder to influence the static mesh in such a way (amongst other things).

One method to address the problem would be to check if the entity was dynamic before applying the velocity using the isDynamic property. You could also try to apply an impulse; since they work on the momentum level, infinite mass kinematic bodies like the triangles wouldn't be affected.
Nostromo
Posts: 4
Joined: Fri Feb 26, 2010 3:45 pm

Re: Strange behaviour after calling a method

Post by Nostromo »

HI!

Yes that solved it! :) I now check the entity to see if it is dynamic.
thanks
Post Reply