Problems with the physics (solved)

hello, I’m trying to learn to work with jme3 and after going through the beginner tutorials i decided to make some experiments, i tried creating a few boxes and applying physics to them but for some reasons i can’t get it to work, the boxes fall with gravity but when they collide i get a NullPointerException (sometimes this only happens after they have completely gone through each other).

I’m using the nightly JME3 version.


package mygame;


import com.jme3.bullet.BulletAppState;

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

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

public class newTest extends SimpleApplication


public static void main (String[] args)


newTest app = new newTest();



private Geometry box1, box2, box3, floor;

private BulletAppState bAS;


public void simpleInitApp()


speed = 0.1f;


this.bAS = new BulletAppState();



floor = createBox(“floor”, 0,-1,0, 10,0.01f,10);


box1 = createBox(“box1”, 0,2,0, 1,1,1);

box2 = createBox(“box2”, 2.1f,2,0, 1,0.5f,0.5f);

box3 = createBox(“box3”, 1,4,0, 2,0.3f,1);






private Geometry createBox(String name, float x, float y, float z, float sizeX, float sizeY, float sizeZ)


Box box = new Box(new Vector3f(x,y,z), sizeX, sizeY, sizeZ);

Geometry geo = new Geometry(name, box);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“Color”, ColorRGBA.randomColor());


CollisionShape colShape = CollisionShapeFactory.createMeshShape(geo);

RigidBodyControl rbc = new RigidBodyControl(colShape, 1);



return geo;




i appreciate any help you can provide :slight_smile:

First of all you are moving the box mesh out of the center, you should set the x,y,z location to the Geometry. To help more I’d need the error output.

this is the part of the output i get when they collide, related to the error:


21/Fev/2011 18:26:40 handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]


at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(

at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.cleanOverlappingPair(

at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.removeOverlappingPair(

at com.bulletphysics.collision.broadphase.DbvtBroadphase.collide(

at com.bulletphysics.collision.broadphase.DbvtBroadphase.calculateOverlappingPairs(

at com.bulletphysics.collision.dispatch.CollisionWorld.performDiscreteCollisionDetection(

at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(

at com.bulletphysics.dynamics.DiscreteDynamicsWorld.stepSimulation(

at com.jme3.bullet.PhysicsSpace.update(

at com.jme3.bullet.PhysicsSpace.update(

at com.jme3.bullet.BulletAppState.render(



at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(



BUILD SUCCESSFUL (total time: 10 seconds)


also, i didn’t quite get what you where referring to, i set the position of the boxes when i create a new Box

You deform the mesh so that it seems that the box is at the location you want it to be. Note that mesh vs mesh collision does not work, mesh is only for static objects, use a BoxCollisionShape or HullCollisionShape for dynamic meshes.

oooohh! so that was the problem, thats what i get for looking for an example in HelloCollision instead of HelloPhysics facepalm

thank you very much for the help :smiley:

Its generally a good idea to just do all tutorials no matter what you want to do initially. After doing that a lot of things should be quite self explanatory.