My character cube falling through my maze (both have collision, I see in debug!)

Basically, it falls through maze, and after it passes the y = 0 axis, it gives me an error that I’ll post asap.



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

java.lang.NullPointerException

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:119)

at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)

at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)

at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.cleanOverlappingPair(HashedOverlappingPairCache.java:219)

at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.removeOverlappingPair(HashedOverlappingPairCache.java:91)

at com.bulletphysics.collision.broadphase.DbvtBroadphase.collide(DbvtBroadphase.java:145)

at com.bulletphysics.collision.broadphase.DbvtBroadphase.calculateOverlappingPairs(DbvtBroadphase.java:235)

at com.bulletphysics.collision.dispatch.CollisionWorld.performDiscreteCollisionDetection(CollisionWorld.java:139)

at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:378)

at com.bulletphysics.dynamics.DiscreteDynamicsWorld.stepSimulation(DiscreteDynamicsWorld.java:339)

at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:324)

at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:311)

at com.jme3.bullet.BulletAppState.render(BulletAppState.java:185)

at com.jme3.app.state.AppStateManager.render(AppStateManager.java:268)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:722)

[/java]





This is the code pertaining to physics:



[java]bulletAppState = new BulletAppState();

stateManager.attach(bulletAppState);



int[] start = (findStart(map.getMapa()));

drawPlayer(start[0], start[1]);



playerShape = new RigidBodyControl(CollisionShapeFactory.createMeshShape((Node) playerNode), 1);

//playerNode.addControl(playerPhy);

//BoxCollisionShape playerPhy = new BoxCollisionShape(new Vector3f(0.2f, 0.3f, 0.0001f));

playerNode.addControl(playerShape);

playerShape.setGravity(new Vector3f(0, -1, 0));

//playerShape.setPhysicsLocation(new Vector3f(30, 120, 1));



landscapeShape = new RigidBodyControl(CollisionShapeFactory.createMeshShape((Node) sceneMasterNode), 0);

sceneMasterNode.addControl(landscapeShape);

System.out.println(start[0] + " " + start[1]);

//SimplexCollisionShape playerShape = new SimplexCollisionShape // fazer collision melhor



bulletAppState.getPhysicsSpace().add(landscapeShape);

bulletAppState.getPhysicsSpace().add(playerShape);



bulletAppState.getPhysicsSpace().enableDebug(assetManager);[/java]

Do you remove objects from the physics space somewhere? This looks like you added or removed an object twice.

The ONLY physics handling ever done is all there.

Went through entire code. Anything physics related, is there.



If it’s relevant:



[java]public void drawPlayer(float xCord, float yCord) {



generationVec = new Vector3f(xCord, yCord, 0.2f);

Box boxShape = new Box(generationVec, 0.2f, 0.3f, 0.001f);

player = new Geometry(“player”, boxShape);

playerImg.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

playerImg.setTexture(“ColorMap”, assetManager.loadTexture(“vivi.png”));

player.setMaterial(playerImg);

player.setQueueBucket(Bucket.Transparent);

player.setMaterial(playerImg);

playerNode.attachChild(player);



}[/java]



this is the Player that sinks



[java]public void makeSquare(int xCord, int yCord, float xSize, float ySize) {



generationVec = new Vector3f(xCord, yCord, 0);

Box boxShape = new Box(generationVec, xSize, ySize, 0.01f);

cube[boxCount] = new Geometry(“terrainSquare”, boxShape);

TangentBinormalGenerator.generate(cube[boxCount]);

//floor.setColor(“Color”, ColorRGBA.Blue);

//floor.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/RustFloor.jpg”));

floor.setTexture(“DiffuseMap”, assetManager.loadTexture(“Textures/RustFloor.jpg”));

cube[boxCount].setMaterial(floor);

sceneMasterNode.attachChild(cube[boxCount++]);



}



public void makeCube(int xCord, int yCord, float xSize, float ySize) {



generationVec = new Vector3f(xCord, yCord, 0.2f);



Box boxShape = new Box(generationVec, xSize, ySize, 0.4f);

cube[boxCount] = new Geometry(“wallSquare”, boxShape);

TangentBinormalGenerator.generate(cube[boxCount]);

//wall.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/CaveWall.jpg”));

wall.setTexture(“DiffuseMap”, assetManager.loadTexture(“Textures/CaveWall.jpg”));

cube[boxCount].setMaterial(wall);

sceneMasterNode.attachChild(cube[boxCount++]);



}[/java]



These are the cube and square(floor) drawing methods.

Then one of the nodes (playerNode, sceneMasterNode) don’t give a proper collision shape. What kind of geometry is in the sceneMasterNode? Can you show a screenshot of the whole scene with debug view on?

The sceneMasterNode is a “maze” I start on a top-down view, it has the maze paths, that are a floor, a square with very low Z dimensions, makeSquare, and big cubes that make up the “walls”, makeCube.

There’s only that: those cubes and squares.



Then there’s the drawPlayer, that’s all… Getting a print

http://i.imgur.com/xJzoM.jpg



http://i.imgur.com/uDQD8.png

Do you generate that mesh yourself as one big mesh? Are you sure all triangles are closed? The static mesh collision shape will only work with proper triangles.

Yes, I used the flycam: I’ll show you give me a sec

Still no luck… no clue what I may be doing wrong, I’ve followed tuts and docs closely though :expressionless:

You know you just put your facebook up on the internet? :stuck_out_tongue:

That ain’t mine, I checked the jpgs and there’s no trace of me hehe

Wouldn’t mind if it had though, never have hidden my identity but don’t exactly go around giving cards either :slight_smile:

With

playerShape = new RigidBodyControl(CollisionShapeFactory.createMeshShape((Node) playerNode), 1);

replaced by

playerShape = new RigidBodyControl(CollisionShapeFactory.createDynamicMeshShape((Node) playerNode), 1);



I can get SOME collision but it’s very buggy, the character will land on maze, and then sink through it very slowly, and suddenly disappear and warp off somewhere

Just create a proper mesh instead of stacking boxes like this or if you have to stack boxes, use box collision shapes instead of using the recursive mesh generation.

Sorry I couldn’t quite understand you…

The map is generated by having an algorithm I made on a side-class make me a int[][] field with values for what will be a wall, a void, or a square(the paths), so it places a cube/square for each value on the int[][] array. How can I do it any differently?

What is “a proper mesh”? What did I do of recursive? I don’t understand really >.>

This is how the map is drawn, using the methods makeCube and makeSquare I showed before:



[java]public void drawMap(int[][] mapa) {

int mapaX = mapa.length;

int mapaY = mapa[0].length;

for (int i = 0; i < mapaX; i++) {

for (int a = 0; a < mapaY; a++) {

if (mapa[a] == 1) {

makeSquare(i, a, 0.5f, 0.5f);

} else if (mapa[a] == 2) {

makeCube(i, a, 0.5f, 0.5f);

}

}

}

}[/java]

you create separate geometries, instead you should create one mesh for the whole maze.

Not quite sure how I’d do that, any tips?

Read the dynamic mesh tutorials and read up on voxel worlds. Essentially you are creating a variant on a box world.

1 Like

did you try to convert everything into 1 node with GeometryBatchFactory.optimize ?