Glitching through Terrain Frequently

Im playing around with terrain. I can spawn my CharacterControl and walk round the world really nicely but usually end up glitching through the terrain and falling into the void.

  • Physics works perfectly for a few minutes
  • I am nowhere near the edge of the terrain grid
  • Usually in steep area or when climbing up a hill
  • Flatter areas seem unaffected
  • No other physics objects in the scene
  • No error messages or debug info

the only “Non standard thing” im doing is using “RawHeightMap.FORMAT_16BITLE” so i can get good height

My character control code is taken from the Q3 example, and looks like this

public void SpawnPlayer(){
        
        if (this.platerisactive == false){
            System.out.println(" AppState_LocalPlayer SpawnPlayer() sp="+spawnpoint);  


            //capsuleShape = new CapsuleCollisionShape(0.4f, 1.8f, 1);
            //player = new CharacterControl(capsuleShape, 0.05f);
           
             player = new PhysicsCharacter(new SphereCollisionShape(0.5f), .01f);
            
            player.setJumpSpeed(25);
            player.setFallSpeed(30);
            player.setGravity(100);
            player.setPhysicsLocation(spawnpoint);

            //add to physicsspace
            ps.add(player);

update() uses the walk method and is not affecting the scenegraph

@Override
    public void update(float tpf) {
        if (platerisactive){
            this.updateplayer(tpf);
        }
    }

private void updateplayer(float tpf){
          
           //set walking speed
        playerMoveSpeed = ( PlayerMovementSpeed * tpf);
          
         //get which way the player is facing in game world 
         camDir = sapp.getCamera().getDirection().mult(playerMoveSpeed);
         camLeft = sapp.getCamera().getLeft().mult(playerMoveSpeed);
         
          //reset the direction to move .. this will prob change each frame anyway
         walkDirection.set(0, 0, 0);
        
        if(PlayerMoveForwards){
           walkDirection.addLocal(camDir); 
           // System.out.println("2-FWDS");
        }
        if(PlayerMoveBackwards){ 
            walkDirection.addLocal(camDir.negate()); 
            //System.out.println("2-right");
        }
        if(PlayerMoveLeft){ 
            walkDirection.addLocal(camLeft);
            //System.out.println("2-back");
        }
        if(PlayerMoveRight){ 
            walkDirection.addLocal(camLeft.negate()); 
            //System.out.println("2-lft");
        }
        walkDirection.setY(0);
        player.setWalkDirection(walkDirection);
        
        //move the blue box to indicate player
        PlayerLocation = player.getPhysicsLocation();
        sapp.getRootNode().getChild("PlayerBlueBox").setLocalTranslation(PlayerLocation);
        
         sapp.getCamera().setLocation(player.getPhysicsLocation());

    }
 


My terrain code is taken from the terrain examples and looks like this


              this.terrain = new TerrainQuad("terrain_"+xpos+"_"+zpos, 33, 513, aheightmap.getHeightMap());
              this.terrain.setMaterial(this.terrainMaterial);
          
              this.terrain.setLocalScale(this.terrainscalexz, this.terrainscaley, this.terrainscalexz); // scale 
              this.terrain.setLocalTranslation(this.worldcenter);
              TerrainLodControl control = new TerrainLodControl(terrain,m.getCamera());
              this.terrain.addControl(control);

              m.getRootNode().attachChild(this.terrain);

              //set up collision detection for the scene by creating a static RigidBodyControl with mass zero.
              this.terrain.addControl(new RigidBodyControl(0));
              m.getStateManager().getState(BulletAppState.class).getPhysicsSpace().addAll(terrain);

              m.getRootNode().attachChild(this.addPlane());

any help is appreciated. ive been struggling for days on this one

1 Like

Have you tried Minie?

1 Like

It was built on bullet (it’s an old project I’m coming back to after a long break). I tried removing jme3-bullet from the build and adding minie. Recompiled. No change same issue

Is there a code Change I need to make or is it a 1:1 replacement

My terrain tiles are 512x512. And there’s a grid 4x4 of them. Is this too much?

1 Like

my guess its just about propelry configuring CCThreshold and other parameters.
Along with physics margin scales/etc.

For example physics should have configured proper steps to avoid clipping(i guess thats issue you got)

I suggest stay with Minie, but try configure physics parameters better. (who knows, maybe you have 1 unit = 1000 meters and physics cant be precise enough)

Remember that bullet-native and Minie both are based on other physics library, so its probably not really JME issue, but physics lib and its configuration.

Also question is what Physics Shape you use for terrain, usually its HeightmapBased one, so not sure if your physics body is proper here.

Is there a code Change I need to make or is it a 1:1 replacement

There are some incompatibilities between jme3-bullet and Minie, but I doubt they’re the issue here.

My terrain tiles are 512x512. And there’s a grid 4x4 of them. Is this too much?

No, that’s fine.

I glanced at your code fragments and didn’t see anything that would cause fall-through issue you describe. However, I don’t usually debug code by reading it. If you put together a complete test case I can execute, I’ll find the root cause of the fall-through for you.

Another approach would be to start with one of the existing test/tutorial apps, see what you’re doing differently, and merge them until the merged code breaks.