Model passing through floor

Hi guys,

I’m having a weird issue with my collisions and I hope you fortunately can help me… :slight_smile:

In my my game, I have a (human) model where each geometry (foot, leg, arm, etc) has an unique collision shape associated to it (in this case, a BulletTriangleMeshShape). This model is placed in an infinite ground (in this case, a BulletPlaneShape). The problem: when the game starts the model pass through the floor instead of standing on the floor. Gravity is ON.

PS: Unfortunately BulletConvexHullShape not fit my purposes once I need know exact points of collisions (I make simulation of touch with this feature).


def create_ground(self):

    # Ground
    shape = BulletPlaneShape((0, 0, 1), 3)
    ground_node = BulletRigidBodyNode("ground")
    ground_node.addShape(shape)
    ground_node.setMass(10000)
    self.physics_manager.attachRigidBody(ground_node)
    ground_np = self.render.attachNewNode(ground_node)

    return ground_np


def create_avatar(self, model_file, name, initial_pos, total_mass, objects_props):

    ## Load the 3d model file using the asset folder relative path
    avatar_np = self.loader.loadModel(Filename.from_os_specific(model_file))
    avatar_np.setName(name)
    avatar_np.setPos(initial_pos)
    avatar_np.setP(90)  # Fix C4D rotation issue

    ## Eliminate any transform with scale and rotate to a shape:
    ##
    ## Scale is bad when it comes to physics. Bullet does support scale, but only to a limited degree and at the
    ## cost of performance. So get rid of any scale within your modeling application (Cinema4D, Blender, Maya,
    ## etc) - look at the exported egg -> does it have transforms with scale?
    ## If this is the issue, I suggest you simply make sure that every object in your modeling application has
    ## the center of mass as origin, and has no rotations and no scale on it.
    avatar_np.flattenLight()

    ## Parse Avatar file to check inconsistences
    for object in objects_props:
        object_np = avatar_np.find("**/" + objects_props['name'])
        if not object_np.isEmpty():

            if type(object_np.node()) == GeomNode:

                ## Create the rigid body
                body_node = BulletRigidBodyNode(objects_props['name'])

                ## If object has mass create a physical shape for it
                perc_mass = float(objects_props['perc_mass'])
                if perc_mass > 0:

                    ## Create the shape used for collisions
                    mesh = BulletTriangleMesh()
                    for geom in object_np.node().getGeoms():
                        mesh.addGeom(geom)
                    shape = BulletTriangleMeshShape(mesh, dynamic=False)
                    body_node.addShape(shape)

                    ## Get the percent of mass from part relative to the avatar and calculate its absolute mass
                    mass = total_mass * perc_mass
                    body_node.setMass(mass)
                    body_node.setDeactivationEnabled(False)

                    self.physics_manager.attachRigidBody(body_node)
                else:
                    print("WARNING: The object '" + objects_props['name'] + "' has no mass defined.")

                body_np = avatar_np.attachNewNode(body_node)
                body_np.setPosHpr(object_np.getPos(), object_np.getHpr())

                # Attach the geom node to rigid body
                object_np.reparentTo(body_np)
                object_np.setPosHpr((0, 0, 0), (0, 0, 0))
        else:
            print("WARNING: The object '" + objects_props['name'] + "' specified in 'objects' list not exists.")

I may be mistaken, but unless you intend your ground to move, it might be worth experimenting with removing the above-quoted line.

With that line in place, I think that you’re creating a ground-plane that is moved by forces, such as gravity or collisions. Without that line, I think that you should end up with a ground-plane that other things can collide with, but that itself is unmoving.

Otherwise, have you tried activating Bullet debug-rendering to visualise what’s happening? Perhaps that will provide some clues.

Hi my friend,

Thanks!

I may be mistaken, but unless you intend your ground to move, it might be worth experimenting with removing the above-quoted line.

It already was without mass and had same problem. I put mass later but I’ll remove it or then I’ll put mass=0.

Otherwise, have you tried activating Bullet debug-rendering to visualise what’s happening? Perhaps that will provide some clues.

I’m using debug node but no clues. When debugging I see the model and its collision shapes crossing the floor. Once camera is attached to render node and not to the ground, I could see the floor falling along the model, but this not happens.

I’ve think of Dynamic flag as false in BulletTriangleMeshShape if that could cause this problem. But in theory this shouldn’t happen because the model is a static/rigid body, should it?

Hmm… I’m not sure. I think that a “static” mesh is one that doesn’t collide or respond to forces–I would expect that you’d want the model to be dynamic, that is, responding to collisions. (See this page, for reference: Bullet Hello World — Panda3D Manual )

Try setting that flag to “True”, see whether that helps.

Oh yes! The link you’ve cited says:

Static object don’t change their position or orientation with time. Typical static objects are the ground or terrain, and houses or other non-moveable obstacles. Here we create a simple plane which will serve as a ground.

So I misunderstood the concept: in my case, the model is dynamic, not static. At home I’ll try change Dynamic to True. I hope that works! Thanks!

1 Like

It’s my pleasure! I hope that it works, and good luck! :slight_smile:

I would expect that you’d want the model to be dynamic, that is, responding to collisions. (See this page, for reference: Bullet Hello World — Panda3D Manual ). Try setting that flag to “True”, see whether that helps.

It finally works! Thanks @ Thaumaturge!

I also had to remove flattenLight line because it messed geometries positions and so the model was created with serious problems (all pieces were flying in a crazy dance… :sweat_smile:). I read here that flattenLight is indicated to static objects (without transformation later), not my case at all!

1 Like