I’m trying to make playerCBox appear and become attached to wherever the camera goes. Then have it collide with colWall and colTall. Could you help me out?
You create a character control but then don’t attach it to anything and don’t add it to the scene. Unless you are doing that in code that we can’t see.
I’ve copied and pasted the code from my previous class where it worked and its throwing this exception. I’ve looked over the tutorials countless times and I have found nothing that can help me.
I’ve attached it to the physics space and have attached the player to the rootnode and nothing is working
You are saying “I’m holding a red piece of string, can you guys tell me how long it is?”
Also, don’t bother to mention exceptions without the stack trace. The strack trace is 99% of the useful information… it also took us how many posts to even hear that you had an exception?
@Override
public void simpleInitApp() {
Box b = new Box(1, 1, 1);
player = new Geometry("Box", b);
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
rootNode.attachChild(player);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.randomColor());
player.setMaterial(mat);
/** A white ambient light source. */
AmbientLight ambient = new AmbientLight();
ambient.setColor(ColorRGBA.White);
rootNode.addLight(ambient);
flyCam.setEnabled(false);
Box wall = new Box(1,1,1); //Makes the basic interior wall
geomWall = new Geometry("Box",wall);
Material wallMat = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
wallMat.setColor("Color",ColorRGBA.Cyan);
geomWall.setMaterial(mat);
Box longWall = new Box(20,1,1);//Makes the vertical walls
geomLongWall = new Geometry("Box",longWall);
Material matLongWall = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matLongWall.setColor("Color",ColorRGBA.Red);
geomLongWall.setMaterial(matLongWall);
Box tallWall = new Box(1,20,1);//Makes the horizontal walls
geomTallWall = new Geometry("Box",tallWall);
Material matTallWall = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matTallWall.setColor("Color",ColorRGBA.Red);
geomTallWall.setMaterial(matTallWall);
//Phsyics stuff
colWall = CollisionShapeFactory.createMeshShape(geomLongWall);
CollisionShape colTall = CollisionShapeFactory.createMeshShape(geomTallWall);
CollisionShape playerBox = new BoxCollisionShape(new Vector3f(1f,1f,1f));
playerCBox = new CharacterControl(playerBox,0.05f);
bulletAppState.getPhysicsSpace().add(playerCBox);
bulletAppState.setDebugEnabled(true);
Anyway, that’s all the time for “20 questions” that I have today. Hopefully someone with more time/patience can continue the game.
As for your original message:
The general approach is wrong anyway… as discussed in other threads. If you move the control around “wherever the camera goes” then by definition you are bypassing physics.
There are already JME tutorials that cover making a character walk around and have the camera follow them.
please note you can download SDK 3.2.4 and open JME → JMETests there and see JME tests as an examples too(with all code for it). there was walking character for sure and many more.