Rolling Sphere hanging on edges of boxes at low speed

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
holophone3d
Posts: 13
Joined: Sun Aug 14, 2011 7:40 pm

Rolling Sphere hanging on edges of boxes at low speed

Post by holophone3d »

I have a rolling sphere that at low speeds is getting hung up on the edges of two aligned boxes in space. The boxes are perfectly aligned in the Z dimension, which is the plane that the ball is rolling on. If the ball has enough momentum it will simply roll over the edge, but since this is a marble game - sometimes the player needs to slowly navigate the marble. In the attached image you can see all of the boxes using the physics drawer, each box boundary is a place where the ball can get stuck.
BoxEdgeStick.JPG
BoxEdgeStick.JPG (52.34 KiB) Viewed 4479 times
A few things I've noticed is that if I don't set the TimeStep settings (the simulation runs slower, but smoother) and this doesn't really seem to be as much of an issue - it hangs for a second but keeps rolling. Since this is a phone game I set the timestep setting to 1/30 seconds to align with the framerate, which feels right in terms of simulation speed, but it made this problem more apparent. I've played with the mass, setting it from .5 to 10 and that doesn't seem to affect it too much in this scenario. Please let me know if there is any other data that I can provide to help provide insight into ways I can mitigate this issue. Thanks a bunch in advance!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rolling Sphere hanging on edges of boxes at low speed

Post by Norbo »

Are the boxes actually boxes, or are they meshes?

Box-sphere has a very direct collision detection system which should not have too many problems with box boundaries. They still exist since the boxes' boundaries are not welded together, but I wouldn't expect you to run into them at slow speeds.

Meshes support boundary welding. If the mesh were constructed ideally, it can completely eliminate the boundary 'bumps.' However, if the mesh is a bunch of separate pieces without index buffer data connecting the objects, then bumps will still exist. In the suboptimal mesh case, the bumps will most likely be more common than the box-sphere case.

If it's a mesh, it can be improved by ensuring that all touching pieces are connected in the index buffer. In other words, adjacent triangles share vertices directly, rather than just having vertices in the same location. The index buffer is used to determine connectivity for bump removal.

Another possibility is that that the simulation is fairly tiny and the AllowedPenetration is large relative to the objects. This would mean it's possible for the object to sink into the ground more relative to its size. When the object comes across a bump, the maximum size of that bump is larger than it would be otherwise. AllowedPenetration defaults to .01. If your sphere is really tiny, like less than 0.25 units in radius, then this may be part of the cause. Mesh welding would still avoid bumps in this case, but scaling the simulation up a bit (if it is small now) would be a good idea. The engine likes things to be in the range from 0.5 to 10.

A lower time step duration may help stabilize things in general. It will mitigate the smallness issue and generally make everything a little more robust. If you can afford it, you can set the time step duration to 1/60f and update the space twice instead of once. Two 1/60f steps will cover the same time as a 1/30f step so things won't look slow. Passing a time into Space.Update(dt) will force the engine to take however many time steps are necessary to go through the accumulated time since the previous frame, but this is generally only used with games which have a variable time step since it requires the use of interpolated entity state for things to look fully smooth.
holophone3d
Posts: 13
Joined: Sun Aug 14, 2011 7:40 pm

Re: Rolling Sphere hanging on edges of boxes at low speed

Post by holophone3d »

Everything is a BEPU primative (Sphere and Box) that are simply aligned with meshes for rendering. Indeed, I do have a small scene (kinda a strange artifact of a few things) currently the radius of the sphere is .08 :( Given where I'm at in my release phase, this isn't something that is easily fixable... Can I adjust the AllowedPentration to help mitigate this issue? I'll also try setting the timestep to 1/60.

UPDATE: Looks like changing allowedPenetration sorted me out. It was exactly what you suggested! The scale advice is super valuable and I'll definitely keep that in mind in the future.

Thanks.
holophone3d
Posts: 13
Joined: Sun Aug 14, 2011 7:40 pm

Re: Rolling Sphere hanging on edges of boxes at low speed

Post by holophone3d »

Now that I have fixed my collision issue, there is one other behavior I would like some advice on. I have an accelerometer based marble maze and when the phone is held at a constant angle, the ball starts slwoly rolling on a flat surface and once it hits a certain speed it seems like it 'breaks' free of some force and almost leaps forward at like double the speed. I've played around with both the static and kinetic friction values (currently set around the .3 for both) but it didn't seem to make much of a difference. I'm wondering is this also related to my relatively small scale or is there an ideal mass or something I should be using? Any advice is appreciated!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rolling Sphere hanging on edges of boxes at low speed

Post by Norbo »

That may be related to the deactivation system. Objects at velocities below the DeactivationManager defined lower limit will be subject to stabilization and deactivation. Stabilization damps energy from the system to let it go to sleep quicker.

I assume you have set the entity.ActivityInformation.AlwaysActive to true already or are changing its velocity manually, which prevents it from going fully inactive. However, stabilization could still be occurring; you can disable it on a per-entity basis by setting entity.ActivityInformation.AllowStabilization to false.

This is indeed related to the small scale since the deactivation manager's (configurable) lower limit would be high relative to the ball's velocity magnitude.
holophone3d
Posts: 13
Joined: Sun Aug 14, 2011 7:40 pm

Re: Rolling Sphere hanging on edges of boxes at low speed

Post by holophone3d »

Makse perfect sense now, I had some code that I used to help ensure that the marble wouldn't get 'stuck' to walls and floors under certain conditions. Your comment clued me in to the fact that it was that code that was creating the strange behavior I was seeing. Instead, I can just use IsAlwaysActive and if needed the stabilization stuff to solve that problem. Your ability to provide advice and guidance that can pinpoint issues and provide solutions so quickly is extremely appreciated. Thanks again!
Post Reply