HelloTerrain Physics


I’ve been going through the jmonkey tutorials and I’m trying to add in physics (collision detection) to the tutorial “HelloTerrain”. So far I’ve managed to create a player (encapsulate the flycam) and add in gravity, the problem is i can’t seem to get collision detection between the terrain and the player so my player keeps falling through the mesh itself. I’m now only stuck on an error that i can’t seem to fix, here is the code i’m having trouble with so far:


import com.bulletphysics.collision.broadphase.Dbvt.Node;

import com.bulletphysics.collision.shapes.CollisionShape;

import com.jme3.bounding.BoundingBox;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.collision.shapes.BoxCollisionShape;

import com.jme3.bullet.collision.shapes.SphereCollisionShape;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.objects.PhysicsCharacter;

import com.jme3.bullet.util.CollisionShapeFactory;

public class Main extends SimpleApplication implements ActionListener {

private TerrainQuad terrain;

public static void main(String[] args) {

Main app = new Main();



public void simpleInitApp() {

bulletAppState = new BulletAppState();


AbstractHeightMap heightmap = null;

Texture heightMapImage = assetManager.loadTexture(


heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);


int patchSize = 65;

terrain = new TerrainQuad(“my terrain”, patchSize, 513, heightmap.getHeightMap());

com.jme3.bullet.collision.shapes.CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(terrain);


terrain.setLocalTranslation(0, -100, 0);

terrain.setLocalScale(2f, 1f, 2f);

Node terrain_holder = new Node();


CollisionShape sceneShape =





Any help or guidance to solve this problem will be very appreciative,


Theres a test class for exactly that.

i belive you forgot to add the collision shape to the bulletappstate:


also, why are you doing this? :

CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(terrain.getSpatial());

seems pointless to me… maybe you were trying to debug or something?

and terrain_holder is not used at all…

finally, i belive normen is talking about this tutorial:


hope this helps…


I’ve got it working! thanks dixil, much appreciated!!

cheers lads :slight_smile: