Attach single ChaseCam to multiple Spatials

I am trying to attach single ChaseCamera to multiple Spatials or add control to multiple spatials. I have written a custom ChaseCam code through which I can attach multiple spatials. But the problem with that is it partially works.
I created 3 boxes and passed all the boxes to the ChaseCam constructor. But when I try to move say box1, box1 and box3 move together and when I try to move box2 only box2 moves.

Geometry[ ] boxes = {box1, box2, box3};
ChaseCam chasecam = new ChaseCam(cam, boxes, inputManager);

public ChaseCam(Camera cam, final Spatial[] target) {
for(int i = 0;i < target.length;i++){

Please help with this.

A control can only belong to one spatial at a time.

How is a single chase cam supposed to follow three different objects anyway? What is the effect you are trying to achieve?

Even I thought so. But I can see the its serving my purpose partially. BTW I want 3 boxes to be stacked upon each other, and I want to drag them left/right/up/down.
With the above code I can see that sometimes box1 moves alone and sometimes box3 also moves along with box1.
I also want the other feature of chasecam where I can change the camera angle dynamically so that I can see the backside of the boxes.
Is there any other way by which I can achieve this?

So all boxes will always move together? If not, what happens when box1 is 400 units away and box 2 moves?

If they are all always together then put them under one node and move the node.

I am sorry I didn’t explain the complete scenario earlier. What I am doing is:

Node subnode1 = new Node();
Node subnode2 = new Node();
Node subnode3 = new Node();




I am casting a ray and colliding it with subnode1, subnode2 and subnode3. Depending upon the collision results I am trying to move the box with which the ray collided.
I just want one box to move at a time. Below are some of the observations:

  1. Select box1 and drag – box1 moves
  2. Select box2 and drag – box3 moves
  3. Select box3 and drag – box1 and box2 moves

The behavior is random. One more interesting observation I made was if I create some dummy boxes and do not attach it to any subnodes or rootNode but still put them in the Geometry[] boxes array, the box1/2/3 will move as expected.

Geometry[] boxes = {box1, box2, box3, dummyBox1, dummyBox2};

You are leaving out important details. Java is not random. Adding elements to an array will not affect the earlier elements unless you are doing something else with them.

Put together a simple test case and post it so we can show you what’s wrong.

You were right about leaving out important details. I fixed my logic and it works fine now. Thank you.
BTW I can still attach single chasecam to multiple spatials.