Hi,
To test the movement of the player I’ve added a simple floor to my game. It consists of a box → geometry with a rigidbodycontrol. The rigidbodycontrol’s mass is set to zero. I also have a prototypish player. It’s a box as well, but tuned with my custom controls to move, look around, and interact. The interesting thing is: The camera is added to the player with a cameranode and follows its movement. In all the tests I just saw dark black background. After senselessly restructuring the controls I thought I’d give it a try with the flybycam to see the general composition. At Vector3f.Zero there’s a tree that serves for orientation. Directly under it there should be a brown floor. Actually there is a kind of floor but it appears and disappears when the camera is moved. You can see it only from specific angles and it pops in and out of view ! The floor is programmed to be completely static. It isn’t referenced in any of the scripts and falls into oblivion after having been added to the rootNode and bulletAppstate. What is wrong ? There is also an explanation for the darkness I’ve seen previously: If you’re quick you can just see the player fall through the floor. It’s as though the floor doesn’t exist but in fact it does.
Here’s some source code. However I don’t think it’ll be of much use. As you can see it’s rather plain.
[java] Box levelmesh=new Box(Vector3f.ZERO, 50, 0.5f, 50);
Geometry levelgeom=new Geometry(“level”,levelmesh);
Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat1.setColor(“Color”, ColorRGBA.Brown);
levelgeom.setMaterial(mat1);
BoxCollisionShape levelshape=(BoxCollisionShape) CollisionShapeFactory.createBoxShape(levelgeom);
RigidBodyControl levelcontrol= new RigidBodyControl(levelshape,0);
//levelcontrol.setKinematic(true);
levelgeom.addControl(levelcontrol);
bulletAppState.getPhysicsSpace().add(levelcontrol);
rootNode.attachChild(levelgeom);[/java]
If the floor is visible or not has nothing to do with physics, if your geometry disappears when still in the camera frustum then the BoundingVolume is wrong. Did you create the floor mesh yourself? Then properly update the BoundingVolume.
I didn’t create the mesh myself:
[java]Box levelmesh=new Box(Vector3f.ZERO, 50, 0.5f, 50);[/java]
However I called
[java]levelgeom.updateModelBound();[/java]
The error still exists and jme informs me that
Updating is not needed in jME3, check your update order if you need to call this.
You are not supposed to call updateModelBound(), did you do that just now or all the time?
I’ve never called this before and only added the call because you said:
Then properly update the BoundingVolume.
The problems were there before as well as after the addition.
Are you talking about your model or the physics debug view (the blue lines)?
Sorry but I’ve never heard of a physics debug view. I’ll learn about it.
The geometry is very simple. In fact it’s the standard start cube stretched to the size 50x0.5x50 , colored brown and equipped with a rigidbodycontrol. I used the exact same code on an other laptop and everything worked fine. Now that I’ve opened the project on this machine there’s the funny problem. It’s strange as it doesn’t use any external assets.
Hm, given that you use Unshaded.j3md idk what could cause that. Can you make a test case for this? This way we can make sure its not your code.
I created a new jme BasicGame and added the following to simpleInitApp:
[java] BulletAppState bulletAppState=new BulletAppState();
stateManager.attach(bulletAppState);
Box levelmesh=new Box(Vector3f.ZERO, 50, 0.5f, 50);
Geometry levelgeom=new Geometry("level",levelmesh);
levelgeom.updateModelBound();
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Brown);
levelgeom.setMaterial(mat1);
BoxCollisionShape levelshape=(BoxCollisionShape) CollisionShapeFactory.createBoxShape(levelgeom);
RigidBodyControl levelcontrol= new RigidBodyControl(levelshape,0);
//levelcontrol.setKinematic(true);
levelgeom.addControl(levelcontrol);
bulletAppState.getPhysicsSpace().add(levelcontrol);
rootNode.attachChild(levelgeom);[/java]
When the game is compiled you see only darkness. Look down and move backwards for a few seconds, then look up.
Okay, just don’t use createBoxShape, its not making a single box but its meant for having a hierarchy of boxes based on part of a scene graph, since it uses BoundingBoxes to compute the size maybe something goes wrong there. Like this the code works:
[java]BulletAppState bulletAppState=new BulletAppState();
stateManager.attach(bulletAppState);
Box levelmesh=new Box(Vector3f.ZERO, 50, 0.5f, 50);
Geometry levelgeom=new Geometry(“level”,levelmesh);
levelgeom.updateModelBound();
Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat1.setColor(“Color”, ColorRGBA.Brown);
levelgeom.setMaterial(mat1);
RigidBodyControl levelcontrol= new RigidBodyControl(0);
//levelcontrol.setKinematic(true);
levelgeom.addControl(levelcontrol);
bulletAppState.getPhysicsSpace().add(levelcontrol);
rootNode.attachChild(levelgeom);[/java]
The RigidBodyControl will create a box shape automatically because the geometry has a box mesh.
That worked. The floor is now solid and remains visible. However the Charactercontrol slides over the ground and slowly sinks in !?
Change the stepHeight (second constructor parameter).
Oh, also a large box is about the worst floor you can choose. Use a PlaneCollisionShape or a proper floor mesh. If the triangles are much larger than the character you’re bound to get issues like that.
Ok, I replaced the BoxCollisionShape with a PlaneCollisionShape. The player no longer sinks into the ground. The floor remains solid and within view.
Thank you.