# How do I – Make boxes collidable?

Home Forum Troubleshooting Physics How do I – Make boxes collidable?

This topic contains 6 replies, has 4 voices, and was last updated by  Maha 1 year, 7 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
• Author
Posts
• #16993

dreigon
1p
Participant

Hi, I’m trying to make a Box (com.​jme3.​scene.​shape.Box) Collidable like the town model is in this tutorial: http://hub.jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_collision
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?
Thanks

#115582

nehon
1894p
Keymaster

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

#115583

dreigon
1p
Participant

Thanks for that
it works now

#115584

dreamer
0p
Participant

Sooo, could anyone please explain what the BoxCollisionShape does?
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

#115585

nehon
1894p
Keymaster

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.

#115586

dreamer
0p
Participant

Wow, thanks a lot! :D
Will do ^_^

#213588

Maha
1p
Participant

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

Spatial enemy_1;
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);

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.