i try to add a collisionShape to a mesh, but a get an exception. Can somebody help me? My code:
Mesh mesh = new Mesh();
mesh.setBuffer(VertexBuffer.Type.Position, 3, new float[]{0, 0, 0, 100, 0, -200});
mesh.setBuffer(VertexBuffer.Type.Index, 2, new short[]{0, 1});
Geometry g = new Geometry(“line”, mesh);

    MeshCollisionShape meshCollisionShape = new MeshCollisionShape(mesh);
    RigidBodyControl bodyControl = new RigidBodyControl(meshCollisionShape, 0f);

The Exception:

at java.nio.Buffer.checkIndex(
at java.nio.DirectShortBufferU.get(
at com.jme3.scene.mesh.IndexShortBuffer.get(
at com.jme3.bullet.util.Converter.convert(
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(
at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(
at mygame.Main.initRoad(
at mygame.Main.simpleInitApp(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(

You are trying to create a collision shape from a line, which isn’t supported

I would say a MeshCollisionShape cant be made from a mesh of type Mesh.Mode.Lines, I imagine it would need a triangle based meshes to work with.

When isn’t possible to set a collision from a line, which alternative can i use. I try to create a road with bordercollision, but i can not use a box for the border. Can i create a box like a line with start and end points?

@thetoucher, i start with jmonkey: can you tell me, how can i do that?

@emoleumassi said: Can i create a box like a line with start and end points?

You can, I would try using a BoxCollisionShape as mentioned on the “Physics: Gravity, Collisions, Forces” page. Just make sure your box isn’t to small or narrow, otherwise objects may pass right through it, and not register a collision.

thank, i known this solution. I try to make a line for a road. I thougt, it is better with a line. If i can make with the box, i 'll be happy. The problem is, how can i say, the problem start by (X1, Y1, Z1) to (X2, Y2, Z2). I think, i can only the box’s size is (x,y,z) and the coordinate, but not the start and end-coordinates

Well, write a little helper factory method to facilitate easy creation by the start-end params rather than the default one. You could also try creating a custom mesh for the road “wall”… idk if it is required to be convex though… anyway you could write a whole helper which would automatically place walls along your whole track, based on its geometry properties and some parameters…