Line connecting two objects

Hi guys,

I want to do something in JME and I want to know from you how this can be achieved in the best way.

The problem I need to solve is to have a line (or thin cylinder) that connects two moving objects. I know that if I attach an object to a Node, it moves around with it. I could move the other end of the connector according to the position of another object with some code in the update() method of some gamestate, but it would be more elegant to let JME do the work.

Any suggestions?

I suppose it depends exactly what you want to accomplish.

Are the two objects always going to be static with regards to one another? If so then you could just attach them all (including the cylinder) to the same node and use setLocalTranslation(x, y, z). As long as they are the correct distance and orientation to begin with then it'll be ok forever.

Or, maybe the objects move with relation to each other, then maybe you could cast a ray between them and get a distance using intersections and get a direction by having a node lookAt() and get the vector3f of the other object. Knowing this you could have a dynamic cylinder made between the two objects.

There are more different (probably better ways to accomplish this but these are examples)


You don't need to use a cylinder: com.jme.scene.shape.Line.

attach a line in the update method with point[0] at object1.getLocalTranslation(); and point[1] at object2.getLocalTranslation(); and make sure to clear the old line off the rootNode before adding the new one.