Sphere falling into a box

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
PSVWizard
Posts: 11
Joined: Fri Aug 02, 2013 11:57 am

Sphere falling into a box

Post by PSVWizard »

Hi there,

I'm quite new to use BEPUPhysics and trying that out for my game I'm working on.

However, I'm running an issue I do not have found any solution in the forum yet.

I've created a small space containing some boxes setting up the ground and sphere being dropped from above.
None of the boxes does have any mass which let them stay where they are regardles of active gravity.
The sphere is falling with a mass setup as expected.

However, one it reaches one box it slows down movement, sinks a bit into the box and after half of a second (rough estimated) it is popping out of the box and rested on it.
I would expect the sphere is immediatly resting on the box.

My box does have a with and length of 2 and my sphere has a radius of 0.3.

Any suggestions to solve the issue would be much appreciated.

-> Sidenode to the Forum-Mods: none of my usual eMail addresses was expected while registering. May be your rules are to restrictive...
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Sphere falling into a box

Post by Norbo »

I can't seem to replicate the behavior. Could you reproduce the issue in the latest BEPUphysicsDemos and post a modified demo for me to debug?

One possible explanation would be a very high CollisionResponseSettings.Softness value. If that has been changed, try setting it back to the default or just 0.
-> Sidenode to the Forum-Mods: none of my usual eMail addresses was expected while registering. May be your rules are to restrictive...
That's interesting; it should just be default phpbb behavior. Have you noticed problems registering on any other phpbb forums?
PSVWizard
Posts: 11
Joined: Fri Aug 02, 2013 11:57 am

Re: Sphere falling into a box

Post by PSVWizard »

Hi Norbo,

thanks for the quick response. I might be not able to create a reproducable project as I'm using BEPUPhysics with the Play Station Mobile SDK. I've downloaded the latest source version and just adopted the class Node and its childs to be public insteat of internal to mitigate any compoiler error.

This is how I set up my stuff:

Code: Select all

protected Space  World {get;set;}

//create the physicsscene
	World = new Space();
	World.ForceUpdater.Gravity = new BEPUutilities.Vector3(0f, -9.81f, 0f);
	BEPUphysics.Settings.CollisionResponseSettings.Softness = 0;

//for each drawable object in the scene create a physics body
	foreach (var drawable in Scene.Drawables){
		if (drawable.Name.Contains("Root")) continue; //do not create a bb for the root node
		//create all boxes without mass except th sphere
		float mass = 0f;
		if (drawable.Name.Contains("Player")){
			mass = 1f;
			Sphere sph = new Sphere(new BEPUutilities.Vector3(drawable.Position.X, drawable.Position.Y, drawable.Position.Z), 0.5f, mass);
			drawable.PhysEntity = sph;
			World.Add(sph);
		} else {
			Box box = new Box(new BEPUutilities.Vector3(drawable.Position.X, drawable.Position.Y, drawable.Position.Z), 2*drawable.Scaling.X, 2*drawable.Scaling.Y, 2*drawable.Scaling.Z, mass);
			box.Orientation = new BEPUutilities.Quaternion(drawable.Orientation.X, drawable.Orientation.Y, drawable.Orientation.Z, drawable.Orientation.W);
			World.Add(box);
		}				
	}
The physics objects are created once the scene graph was loaded from a FBX file. However, the final result looks like this:
Image

The red boxes are made visible with a debug drawer directly linked with the physics objects (Similar to the BoundingBoxDrawer in the Demo's) the real objects are rendered with my graphics engine.

As you can see at the end of the updates when the sphere is resting it some how a bit sitting inside of the box.
I've tryed to give you better visibility with the following movie and a bit changed camera position:


Thanks in advance for your support.


----------------------
That's interesting; it should just be default phpbb behavior. Have you noticed problems registering on any other phpbb forums?
'No I haven't had any issues with my email to any bb forums. May be the latest version are more restrictive nowadays ;)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Sphere falling into a box

Post by Norbo »

That video looks roughly like expected behavior. Here's a few notes:

1) The CollisionDetectionSettings.AllowedPenetration defaults to 0.01, which will be barely visible on those scales (as shown in the pictures/video). Objects tend to rest at somewhere between 0 and CollisionDetectionSettings.AllowedPenetration depth; any deeper results in penetration resolution forces which push the object back to AllowedPenetration. Reducing AllowedPenetration could help some, but can introduce jitter. (Manifold types that generate speculative contacts will fare better, but they are not universal and knowing which pairs use speculative contacts requires excess familiarity with the internal implementation.)

2) The initial penetration is caused by discrete time stepping. The sphere just moves forward in time and finds itself in collision and has to deal with it after the fact. While you could enable continuous collision detection and tune it such that it's ultrasensitive, it's probably not worth it; oversensitive motion clamping can actually hurt behavior. (Speculative contacts would deal better with this particular case, and while the engine does use speculative contacts in some manifolds, it does not use them for CCD at the moment to avoid some corner case wonky behavior.)

3) Near the moment of impact, it looks like the JIT or some other lazy initialization kicks in and causes a frame hiccup. If this was part of the behavior you were wondering about, it should be a one-time event. You can 'warm up' the simulation during load to get it out of the way early.
PSVWizard
Posts: 11
Joined: Fri Aug 02, 2013 11:57 am

Re: Sphere falling into a box

Post by PSVWizard »

3) Near the moment of impact, it looks like the JIT or some other lazy initialization kicks in and causes a frame hiccup. If this was part of the behavior you were wondering about, it should be a one-time event. You can 'warm up' the simulation during load to get it out of the way early.
Thanks for the quick rsponse again.

What did you mean by "warm up" the simulation? Is there something that could be preparing while loading the objects?
Once the sphere hot the ground everything runs very smooth and the sphere is rolling around :)

BR PSV Wizard
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Sphere falling into a box

Post by Norbo »

The minimum required 'warm up' depends on where the hiccup is coming from, but a brute force warm up which should definitely take care of it could just be creating a tiny mock simulation at load time which involves the same resources.

For example, in this case, the load could spawn a box and a sphere in collision, run a single frame worth of simulation, remove the objects, and then proceed with regular initialization. This would force the JIT to hit all the common simulation code and would require the population of all related ResourcePools.
PSVWizard
Posts: 11
Joined: Fri Aug 02, 2013 11:57 am

Re: Sphere falling into a box

Post by PSVWizard »

Hi norbo,

thanks. I'll try this approach.

BR PSVWizard
Post Reply