Strange gravity with vehicle

I’m a little confused as to why when the vehicle moves onto an object that is not the ground, the gravitational effect seems to stop. As the video shows, the motorbike acts exactly as expected on the floor bumps, but when it gets onto the wooden planks, the motorbike does not slow down. It rides along at the same speed regardless of the inclining slope.

[video]http://www.youtube.com/watch?v=DI4EEPGg4GI[/video]

Ignore the uber flip at the end, that’s probably suspension related. I continued the line of planks downhill after I made the video and it doesn’t speed up downhill either. This behaviour is only apparent when I go onto the planks. On the floor it behaves as I expect, both up and down hill.

Strange. If I add the planks of wood programatically it works as expected (gravity affects the motorbike climbing the plank). If I add the planks to a scene by right-clicking a spatial and selecting “Add in SceneComposer” it causes the issue. I rotated the planks using the rotate tool in the scene composer. I seems as if the rotated plank when added this way is being treated as if it isnt rotated.

Well, normally this does not happen, at least for my the vehicles does behave as expected no matter what surface they are on.

As long as the collisions are calcualted correctly this rortation stuff can not be the issue, as the physic engine does really onla care about the collisions, there is nothing other special in it.

You might want to see if different shapes are created by this, or something else is off.

I think the issue is as a result of using the rotate tool in the scene composer. It’s as if the rotation is treated as if it wasn’t rotated at all.

@jayfella said: I think the issue is as a result of using the rotate tool in the scene composer. It's as if the rotation is treated as if it wasn't rotated at all.

The rotate tool rotates the physics object if you have added a collision shape, maybe this is the reason for the behavior you see?

[java]
Spatial scene = this.getAssetManager().loadModel(“Scenes/newScene.j3o”);
scene.addControl(new RigidBodyControl(0));

rootNode.attachChild(scene);
bulletAppState.getPhysicsSpace().add(scene);
[/java]

The reason I did it this way is because if I add a RigidBody to the scene like below, it crashes with a nullpointer when I try to add the scene to the physics space. The error is caused by

So I guess it’s me and not a bug, but I’m not entirely sure where I’m going wrong. My intention is to be able to drive across the terrain, drive up the planks, and additionally have objects with mass that react to being driven over and pushed. It would be majorly beneficial to be able to use the scene composer to do that as I’m sure you can imagine.

So you have one big collision shape, probably not ideal. Also you cannot have a terrain collision shape and normal geometry in one factory-generated collision shape.

Is there some documentation I could read? I can do this programatically and everything works, but I figured the whole point of the scene composer was to do exactly as I hoped without having to programatically create it. The TerrainQuad’s in the scene dont have any collision shapes associated with them in the SceneExplorer. Would I have to traverse over each child in the scene and check instanceof’s to create collidable terrain and add it to the physics space, and then through every object to check if it has a rigidbody and add them too? As I said, my intention is to have both static (zero mass) objects that I can drive up and have it react to gravity, and in addition, objects with a mass greater than zero that react to being driven over or pushed.

Yeah, then you need separate physics controls. There is documentation about the physics system, yes. Check the link on the right or the main documentation link on the top of the page.

Ok I came up with a solution that allows me to use the SceneComposer. If you set the mass greater than zero in the physicscontrol it will automatically make a mesh shape. It may take a short while on some levels, but it only occurs when the level loads, so I don’t care, plus it makes creating levels a piece of cake. Thanks for the help normski.

[java]
Spatial scene = this.getAssetManager().loadModel(“Scenes/newScene.j3o”);
traverseForPhysics((Node)scene);
[/java]

[java]
private void traverseForPhysics(Node parent)
{
for (Spatial child : parent.getChildren())
{
if (child instanceof TerrainQuad)
{
TerrainQuad tq = (TerrainQuad)child;

            float[] heightmap = tq.getHeightMap();
            tq.addControl(new RigidBodyControl(new HeightfieldCollisionShape(heightmap, tq.getLocalScale()), 0));

            this.bulletAppState.getPhysicsSpace().add(tq);
        }
        else if (child instanceof Node)
        {
            Node node = (Node)child;

            RigidBodyControl physicsControl = node.getControl(RigidBodyControl.class);

            if (physicsControl != null)
            {
                if (physicsControl.getMass() > 0)
                {
                    float mass = physicsControl.getMass();
                    node.removeControl(physicsControl);

                    CollisionShape shape = CollisionShapeFactory.createDynamicMeshShape(child);
                    RigidBodyControl rigidBody = new RigidBodyControl(shape, mass);

                    child.addControl(rigidBody);

                    bulletAppState.getPhysicsSpace().add(child);
                }
                else
                {
                    bulletAppState.getPhysicsSpace().add(child);
                }
            }

            if (node.getChildren().isEmpty() == false)
            {
                traverseForPhysics(node);
            }
        }

    }

}

[/java]

Normski? Anyway, setting a mass > 0 makes a dynamic collision shape (hull), not a mesh shape. When the mass is zero a mesh collision shape will be created. This is because mesh collision shapes cannot be dynamic and an object with mass == 0 is immobile. You can create both types in the SDK already.