HelloCollsion shaking camera with custom content

Please forgive me for being new. I have had a good try at solving this, but I have not managed to figure out why I’m having this problem.



I want to create custom blocks at runtime for a small map(like a maze). I was testing the HelloColision example by adding a box. I have a problem with the camera shaking when coming into contact with the box, either as a floor or a wall. The mesh that loads with the HelloCollison works perfectly, but any content I add does not. So I recognise I must be doing something wrong. Can anyone help?



// add a test floor

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

mat.setBoolean(“UseMaterialColors”, true);

mat.setColor(“Ambient”, ColorRGBA.Gray);

mat.setColor(“Diffuse”, ColorRGBA.Gray);

Box floor = new Box(Vector3f.ZERO,20f, 1f,20f); //size of floor

Geometry geom = new Geometry(“Floor”, floor);

geom.setMaterial(mat);

geom.setLocalTranslation(0, 0f, 0f);

CollisionShape wallShape = CollisionShapeFactory.createBoxShape(geom); //I have tried mesh shape too

geom.addControl(new RigidBodyControl(0));

rootNode.attachChild(geom);

bulletAppState.getPhysicsSpace().add(geom.getControl(RigidBodyControl.class));

bulletAppState.getPhysicsSpace().enableDebug(assetManager);

[java]Material mat = new Material( assetManager, “Common/MatDefs/Light/Lighting.j3md”);

mat.setBoolean(“UseMaterialColors”, true);

mat.setColor(“Ambient”, ColorRGBA.Gray);

mat.setColor(“Diffuse”, ColorRGBA.Gray);

Box floor = new Box(Vector3f.ZERO,20f, 1f,20f); //size of floor

Geometry geom = new Geometry(“Floor”, floor);

geom.setMaterial(mat);

geom.setLocalTranslation(0, 0f, 0f);

CollisionShape wallShape = CollisionShapeFactory.createBoxShape(geom); //I have tried mesh shape too

geom.addControl(new RigidBodyControl(0));

rootNode.attachChild(geom);

bulletAppState.getPhysicsSpace().add(geom.getControl(RigidBodyControl.class));

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

Are these 2 different issues:

@oldrobot said: I have a problem with the camera shaking when coming into contact with the box, either as a floor or a wall.

@oldrobot said:
The mesh that loads with the HelloCollison works perfectly, but any content I add does not.


?

The shaking sounds like the could just be phyics engine doing its thing... when two object collide often they often "bounce", and if your camera is attached to one of these objects, it too will bounce which would appear as a kind of shaking.

"but any content I add does not. " ... in what way does it "not" ? Are you saying it's only your objects that cause this shake or they are doing something else weird ?
1 Like

Hi. Thank you for your reply,



Yes the shaking is caused by the bounce as the cam is attached to an object. However the bouncing only occurs on the geometry that I add and not with the existing geometry in the HelloCollison example.



only the box I have added causes this shake, nothing else wierd is happening. Its just i need to generate all my geometry at runtime and the bouncing/shaking effect is stopping me doing this as it would not be good in a game.



There is no bounce on the loaded mesh in the example, i want to replicate that, but with geometry created at runtime. Its only going to be boxes - nothing more complex.



Any suggestions greatly welcomed, as its the only thing holding my project up!

@thetoucher how to solve the issue with camera shaking if the camera is attached to a character?

Huge box is the worst floor possible.

Hi, thank you for your help.



Prompted by you suggestion I have tried smaller sqaures, as this is infact how the level will be generated. I have found that even a box of size 2

exhibits the same issues… However if I put several of them together it is fine! Will try with quads now to reduce the overhead of so many blocks.



[java]// add a test floor

Material mat = new Material( assetManager, "Common/MatDefs/Light/Lighting.j3md");

mat.setBoolean("UseMaterialColors", true);

mat.setColor("Ambient", ColorRGBA.DarkGray);

mat.setColor("Diffuse", ColorRGBA.DarkGray);

Box floor = new Box(Vector3f.ZERO,8f,1f,8f);//size



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

for(int w=0;w<20;w++){

Geometry geom = new Geometry("Floor"+(iw), floor);

geom.setMaterial(mat);

geom.setLocalTranslation(i
8,1f, w*8);

CollisionShape wallShape = CollisionShapeFactory.createBoxShape(geom);

geom.addControl(new RigidBodyControl(wallShape,0));

rootNode.attachChild(geom);

bulletAppState.getPhysicsSpace().add(geom.getControl(RigidBodyControl.class));



}

}

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

Just remember that graphics card etc will happily eat huge numbers of vertexes but large numbers of objects can slow things down fast…

Thank you zarch. Yea I am wanting to avoid that issue. Can the boxes of a floor, be combined at runtime into 1 object? As I have a ceiling an walls to put in also!



Or is there any other way to aproach this?



Thanks again for your help.

Yeeh, there are options like the geometry batch factory and the batch node…or you can export it as one model…or you can generate it as one model in a modelling program.



(I.e. don’t generate a square in your code, generate a mesh). Look at the terrain stuff for example to see how that does it.



You need to draw the right line between putting everything in one model and being able to efficiently cull non-visible stuff…and between being able to move stuff without needing to modify meshes etc…so don’t try and put everything in one but try and divide your scene up logically.

Thank you for that, the geometry batch factory really makes a difference.

This has soved the problem for the floor. For the walls I used DynamicMeshShape as this worked better for some reason.



Thank you for your ideas and imput. The idea of creating a few meshes will probably help to cut down on object.

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


Thanks for all ur help!