How do I - Make boxes collidable?

Hi, I’m trying to make a Box (com. jme3. scene. shape.Box) Collidable like the town model is in this tutorial:

I cant seem to make a physics node out of a box. Is there another way to do this?

Should I just create a model like the town but just a box to get around this or is there a way to createa physics node out of a box?


There is a BoxCollisionShape

Do something like that

Box cube = new Box(Vector3f.ZERO, 1.0f, 1.0f, 1.0f);

Geometry cubeGeom = new Geometry(“cube”, cube );

PhysicsNode cubeNode= new PhysicsNode(cubeGeom, new BoxCollisionShape(new Vector3f(1.0f, 1.0f, 1.0f)),1.0);

Thanks for that :slight_smile:

it works now

Sooo, could anyone please explain what the BoxCollisionShape does? :slight_smile:

Is the Node considered to be a Box for physics-purposes, or is the Box only for rough collision detection with a more accurate one still taking place based on the visible model?

If it’s really just a Box, could anyone post a snippet of code to get collision to work for models (e.g. Oto)?

That’d be great, as my attempts with the CollisionShapeFactory so far dumped when trying to work with our beloved golem :frowning:

Well…when you set a BoxCollisionShape for a model, it means it will be considered as a box in Physic world. So any collision will be computed as it was a box.

For compound collision shape look at the tutorial linked in the first post.

For character collision the simplest way is to make a CapsuleCollisionShape or a SphereCollisionShape and use the PhysicsCharacterNode.

Look at the TestWalkingChar for Oto collision, the createCharacter method in particular.

Wow, thanks a lot! :smiley:

Will do :slight_smile:

Can i ask a question ?
i want to make a ship collidable as this box

Spatial enemy_1;
enemy_1 = assetManager.loadModel(“Models/Boat Fishing 01/boat_fishing_01.obj”);
enemy_1.scale(0.1f, 0.09f, 0.08f);
enemy_1.rotate(0f, 1f, 0.0f);
enemy_1.setLocalTranslation(100.0f, 115.0f, 100.0f);
Thanks in advance :slight_smile: