Collision detection for Mesh not happening

Hi,

I am trying to add the capability of collision detection to Line( com.jme3.scene.shape.Line ). But some how collision isn’t detected. Below is the snippet and exception.

[java]
Line link = new Line(start, end);
Geometry geo = new Geometry(“Link”, link);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setTexture(“ColorMap”, assetManager.loadTexture("/Textures/stripes_1.png"));
mat.setColor(“Color”, ColorRGBA.White);
geo.setMaterial(mat);

MeshCollisionShape level_shape = new MeshCollisionShape(geo.getMesh());
RigidBodyControl rgbc = new RigidBodyControl(level_shape);
geo.addControl(rgbc);

rootNode.attachChild(geo);

[/java]

Exception
java.lang.IndexOutOfBoundsException
at java.nio.Buffer.checkIndex(Unknown Source)
at java.nio.DirectShortBufferU.get(Unknown Source)
at com.jme3.scene.mesh.IndexShortBuffer.get(IndexShortBuffer.java:53)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:91)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(MeshCollisionShape.java:68)
at com.XXX.lib.jme3d.Launcher.createInterPlaneLinks(Launcher.java:480)
at com.XXX.lib.jme3d.Launcher.simpleInitApp(Launcher.java:499)

Can someone please let me know what might be the issue with the above code? If you feel the the MeshCollisionShape is not suitable please suggest the suitable one.

You can’t really collide with a line, you need triangles. It won’t work with a geometry ray collision either. You can use a thin cylinder or something solely for collision detection, but it might not play well with actual physics as the triangles will be very small.

Thanks. Any alternatives to using a Line? You said even Cylinder will help. :frowning:

@shrikantkhapare said: Thanks. Any alternatives to using a Line? You said even Cylinder will help. :(

So what part is unclear about that?

Can Cylinder be used as an alternative to Line? I mean by casting a ray can the collision on a Cylinder detected?

@shrikantkhapare said: Can Cylinder be used as an alternative to Line? I mean by casting a ray can the collision on a Cylinder detected?

Did you try it?