BoxCollisionShape won't appear

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?

//Phsyics stuff
    colWall = CollisionShapeFactory.createMeshShape(geomLongWall);
    CollisionShape colTall = CollisionShapeFactory.createMeshShape(geomTallWall);
    CollisionShape playerBox = new BoxCollisionShape(new Vector3f(1f,1f,1f));
    playerCBox = new CharacterControl(playerBox,1f);
    bulletAppState.getPhysicsSpace().add(playerCBox);
    bulletAppState.setDebugEnabled(true);

Looks like you never attach it to the root node.

It says can’t convert character control to spatial

What is “it” in “it says”?

You give us no information to help you, really.

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 highly recommend that you do the JME tutorials.

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

We can’t see that so we can’t help you.

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?

You may want to read: mikeash.com: Getting Answers

We will be able to help you much better if you provide enough information to help you from the beginning.

On the 6th line i attach it to the physics space and have already attached the player geometry to the rootnode I don’t know what else you need.

Where?

@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);        

Thats all my code

You never attach playerCBox to the player.

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.

Good luck with your game.

Can you link me anything then because I can’t find anything

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.

3D scene with first person character: https://wiki.jmonkeyengine.org/jme3/beginner/hello_collision.html

Other tutorials can help add a chase camera, etc…

Since you are new to programming, you should really read and do all of the tutorials: https://wiki.jmonkeyengine.org/jme3.html#tutorials-for-beginners

I’ve been looking at hello collision and they don’t attach anything to the character control

Examples of physics plus 3rd-person camera may be found JmeTests:

But you won’t learn Java quickly by trial and error. Before trying to modify example code, I suggest you study the fundamentals:

That’s right… and it works anyway.

Is there something I’m missing here because it seems that it still goes through walls and it doesn’t follow the geometry

 //Phsyics stuff
    colWall = CollisionShapeFactory.createMeshShape(geomLongWall);
    CollisionShape colTall = CollisionShapeFactory.createMeshShape(geomTallWall);
    CollisionShape playerBox = new BoxCollisionShape(new Vector3f(1f,1f,1f));
    playerCBox = new CharacterControl(playerBox,1f);
    bulletAppState.getPhysicsSpace().add(playerCBox);
    bulletAppState.setDebugEnabled(true);        
    
    Node playerNode = new Node("player Node");
    playerNode.addControl(playerCBox);
    rootNode.attachChild(playerNode);
    playerNode.attachChild(player);
    Vector3f playerLocation = player.getLocalTranslation();
    playerCBox.setPhysicsLocation(new Vector3f(playerLocation.x,playerLocation.y,1f));

@Override
public void simpleUpdate(float tpf) {
    
      Vector3f playerLocation = player.getLocalTranslation();
      cam.setLocation(new Vector3f(playerLocation.x,playerLocation.y,50f));
      playerCBox.setPhysicsLocation(new Vector3f(playerLocation.x,playerLocation.y,1f));
      
      
}

Only going to say this ONE MORE TIME!!!

IF YOU MANUALLY POSITION YOUR CHARACTER CONTROL THEN YOU ARE BYPASSING PHYSICS.

Repeat as needed. It’s like you are using a Star Trek transporter to beam your character all around and then wondering why walls don’t matter.

Do the tutorial. Not just cut and paste from it. Actually run it. Take it apart. Break it. Fix it again. Learn Java, etc…

1 Like

I have and they manually position their character control too.

    player.setPhysicsLocation(new Vector3f(0, 10, 0));

Repeat as needed. It’s like you are using a Star Trek transporter to beam your character all around and then wondering why walls don’t matter.

he he, i think it explain it best way as possible :slight_smile: This should be pinned as physics legendary quote :smiley:

@Bortax

to translate it a little, you need use physics move(impulse/etc) methods so physics will position it itself, not warping(setting raw location) on own.

for an CharacterControl there is setWalkDirection if im not wrong.