Hi, I am having some trouble with the collision detection with jme3. I have been following the tutorial, trying to test the collision detection with my own figure. But, when I think I have it down, I go straight through the object. Heres the method for it:
[java]public class Physics {
private Spatial sceneModel;
private RigidBodyControl landscape;
private CharacterControl player;
public Physics (Game game) {
sceneModel = game.getAssetManager().loadModel("Models/bunny/bunny.j3o");
game.getRootNode().attachChild(sceneModel);
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
landscape = new RigidBodyControl(sceneShape, 0);
sceneModel.addControl(landscape);
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
}
}[/java]
Is there something else that I need to include? Or…
I changed my code a bit following the directions of the tutorial, and it still doesn’t work. Now I don’t really know what to do. Heres the new code:
[java]public class Physics {
private Spatial sceneModel;
private RigidBodyControl landscape;
private CharacterControl player;
private BulletAppState bulletAppState;
public Physics(Hyphadite hypha) {
bulletAppState = new BulletAppState();
hypha.getStateManager().attach(bulletAppState);
sceneModel = hypha.getAssetManager().loadModel("Models/bunny/bunny.j3o");
hypha.getRootNode().attachChild(sceneModel);
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
landscape = new RigidBodyControl(sceneShape, 0);
sceneModel.addControl(landscape);
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
bulletAppState.getPhysicsSpace().add(landscape);
bulletAppState.getPhysicsSpace().add(player);
}
I don’t think so… I think I’m following all of the physics/collision steps in the HelloCollision tutorial. Do I need to include all of the other stuff like the keys and movement?
I got a NullPointerException on the debugging line, and I tried putting it on both the Physics class and the main class, and I get the same thing. I am using private static PhysicsSpace physicsSpace; to use the debug method on your link.
Heres the code:
[java]public class Hyphadite extends SimpleApplication {
private static Hyphadite hypha;
private static PhysicsSpace physicsSpace;
public static void main(String[] args) {
hypha = new Hyphadite();
hypha.setShowSettings(true);
hypha.start();
}
public void simpleInitApp() {
Physics physics = new Physics(this);
Init_Map i_map = new Init_Map(this);
physicsSpace.enableDebug(assetManager); //Line 23
}[/java]
Note: the enableDebug is deprecated now, is that why?
Heres the exception. It is thrown on the enableDebug line:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at hyphadite.Hyphadite.simpleInitApp(Hyphadite.java:23)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:722)
I fixed it, but I don’t really see a difference. Is the debugging the red lines of code in the output? I’ve been getting those every time I run the app. Heres the new code, in case I misplaced it or something:
[java]public class Physics {
private Spatial sceneModel;
private RigidBodyControl landscape;
private CharacterControl player;
private BulletAppState bulletAppState;
private PhysicsSpace physicsSpace;
public Physics(Hyphadite hypha) {
physicsSpace = new PhysicsSpace();
physicsSpace.enableDebug(hypha.getAssetManager());
bulletAppState = new BulletAppState();
hypha.getStateManager().attach(bulletAppState);
sceneModel = hypha.getAssetManager().loadModel("Models/bunny/bunny.j3o");
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
landscape = new RigidBodyControl(sceneShape, 0);
sceneModel.addControl(landscape);
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
hypha.getRootNode().attachChild(sceneModel);
bulletAppState.getPhysicsSpace().add(landscape);
bulletAppState.getPhysicsSpace().add(player);
}