Smooth Floors

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
kokkivos
Posts: 19
Joined: Sat Apr 13, 2013 6:18 pm

Smooth Floors

Post by kokkivos » Fri Nov 14, 2014 8:26 pm

Hey there,

I'm having a problem with constructing a floor for an arena. I want to be able to destroy individual pieces of the floor, so I created models that define the shapes I want, and used their vertices to create entities using a ConvexHullShape that I place in the world.

The problem is that the player's cylinder will get stuck on the edges between floor pieces, even when the vertices are the exact same height. I think I've read somewhere on these forums that the edges of a shape have a sort of "bump" that causes this, and that the solution is to join the meshes? I want the pieces to be separate, though, so that I can take out individual pieces. How can I go about achieving this?

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

Re: Smooth Floors

Post by Norbo » Fri Nov 14, 2014 9:49 pm

The bump occurs because the sliding object is actually ever so slightly penetrating the surface. When the boundary between two shapes is hit by the sliding object, it will generate a contact with the side of the next object as if it wasn't obscured by the adjacent object. ConvexHullShapes do not have any concept of adjacency or occlusion.

That side contact can bump the sliding object or, in really bad cases, just stop it completely.

This picture shows the situation with exaggerated penetration and margins:
marginbump.png
marginbump.png (4.42 KiB) Viewed 2109 times
The blue rounded boxes are the collision margins of the shapes. All convex shapes have them for collision detection reasons. The ground boxes, in the case assumed to be ConvexHullShapes, have external collision margins that expand beyond the actual specified vertices (represented by the black boxes). The cylinder shape has an internal collision margin.

These collision margins offer a way to mitigate the bumps. If the collision margin of the cylinder is made larger relative to the penetration, the generated contact normal will tend to be closer to straight up like the surrounding surface. This makes the bump smaller. Combined with something like the CharacterController's VerticalMotionConstraint to prevent micro-launches, the bumps should be essentially invisible.

(Side note: meshes have a lot of rather complicated logic dedicated to handling adjacency through the index list. It allows the collision system to remove or correct contacts that are not consistent with the continuous surface described by the vertex and index lists. It can pretty much eliminate bumps regardless of collision margins. Unfortunately, it's a lot harder to extend this to completely arbitrary shapes.)

kokkivos
Posts: 19
Joined: Sat Apr 13, 2013 6:18 pm

Re: Smooth Floors

Post by kokkivos » Fri Nov 14, 2014 11:05 pm

Ah! I see. So then, where should I be setting the collision margins?

I see that I can alter the value of CollisionDetectionSettings.DefaultMargin, but I'm guessing that would change every entity's margin. After testing, changing that property does seem to solve my problems, but I don't know if it's the best solution.

I found the collisionMargin field in ConvexShape's source code, so in theory I could alter that for just the floor or the cylinder; I can't see a way to specify a collisionMargin, though, since it is a protected internal field, which is only ever set to the default margin value.

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

Re: Smooth Floors

Post by Norbo » Sat Nov 15, 2014 3:07 am

The ConvexShape.CollisionMargin property is settable. I'd probably change the margin of the character before the floor, unless there are a lot of other objects having the same bumpy issue with the floor.

kokkivos
Posts: 19
Joined: Sat Apr 13, 2013 6:18 pm

Re: Smooth Floors

Post by kokkivos » Sat Nov 15, 2014 5:16 am

Oh. Silly me, there it is. Thanks Norbo, you're awesome! :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests