Oct 20, 2010 at 1:07 AM
Edited Oct 20, 2010 at 4:08 AM
I am trying to resolve the mesh/box collisions issues I am having. My bigger boxes seem to do collision alright. My smaller boxes, such as the ones I use for arms and legs, will fall through my mesh if they are not aligned with the normal of
the floor they're colliding with. This should be something you could test in your holodeck example:
My CRigidBody inherits your RigidBody class. All it really does is requires me to do things in a particular order, to make sure I don't make any boo-boos. It helped me catch a few hard-to-find mistakes that evolved from over non-stop tweaking
public CRigidBody(Part part, Material material)
private void CompleteConstruction()
//Applies a default transform of no scaling, at the origin, no rotation.
Transform identity = new Transform(1f, Vector3.Zero, Quaternion.Identity);
//Sets the MassProperties based on the shape. If a cube, uses MassProperties.FromCuboid, etc.
AssignedMass = DefaultMass; //DefaultMass is just a floating point number comparable to the object's size. It is often changed after construction to be the item's mass.
//Sets the world to be at the origin.
This is how I am creating the box part. That returned part is added to a RigidBody's skin, as shown in the constructor above. I have the material to be 0 for elasticity and roughness (I assume that's okay, right?).
private static PolyhedronPart CreateBoxPart(Vector3 vertices)
ConvexHull3D hull = new ConvexHull3D(vertices);
CompiledPolyhedron compiled = hull.ToPolyhedron();
PolyhedronPart part = new PolyhedronPart(compiled);
And I use the following to assign the mass:
MassProperties = MassProperties.FromCuboid(value, myModelSpaceBox.Max - myModelSpaceBox.Min);
My mesh parts are even more simple:
private static MeshPart CreateMeshPart(Vector3 vertexPositions, int indices)
return new MeshPart(vertexPositions, indices);
I did have to reverse the winding of my triangles for collisions to work at all.
Originally, I was setting my MassProperties to be MassProperties.Immovable, but that did not work at all. I had to use Freeze() instead, and use:
MassProperties = MassProperties.FromTriMesh(value, myVertexPositions, myIndices, out centerOfMass);
And this is how I am throwing my box at my mesh, just for clarity's sake:
Vector3 impulse = myCamera.Forward * 10f;
Vector3 offset = Vector3.Zero;
arrow.Body.ApplyImpulse(ref impulse, ref offset);
Box on box collision is darn near perfect. My mesh on box is iffy then the box isn't axis-aligned, particularly the smaller they are (mass and size), like arms and legs.
Cheers, and thank you for all your help!