I'v been working days to get the camera work but it still doesnt work!

Hai!

I got a car game.

And the camera is attached to a node.

this node is attached to the car so u can see it from behind and it follows.

But, when the car flips, so does the camera, so when I flip all I see is the black side of the ground!



I'v tried to fix this is all possible ways possible!

Using ChaseCamera doesnt do anything better!

All equations ends up in being useless!



Heres my moste recent attempt (attempt no. 432):

   public void updateCam(Camera cam){
      float y = 0;
      float value = 50;
      //y =  camNode.getWorldTranslation().y -(Car.getWorldTranslation().y +10);
      System.out.println("


");
      System.out.println("camNode: "+camNode.getWorldTranslation().toString());
      System.out.println("Car: "+Car.getWorldTranslation().toString());
      System.out.println("OldVec: "+oldVec.toString());
      if (Car.getWorldTranslation().toString().equals("(0.0, 0.0, 0.0)")){
         camNode.getLocalTranslation().set(oldVec);
      } else {
         if (camNode.getWorldTranslation().y < (Car.getWorldTranslation().y+value)){
            float numb = -camNode.getWorldTranslation().y;
            float CarY = Car.getWorldTranslation().y + numb + value;
            System.out.println("numb: "+numb+" CarY: "+CarY);
            y = CarY-numb;
         } else {
            float numb = -(Car.getWorldTranslation().y  + value);
            float camY = camNode.getWorldTranslation().y + numb;
            System.out.println("numb: "+numb+" camY: "+camY);
            y = camY- numb;
         }
         Vector3f extraVec = Car.getLocalRotation().getRotationColumn(0).mult(30);
         extraVec.y = 0;
         camNode.getLocalTranslation().set(extraVec.x,y,extraVec.z);
         oldVec = camNode.getLocalTranslation();
         System.out.println("Result: "+y);
      }
      //camNode.lookAt(CarFront.getLocalTranslation(), new Vector3f(0,1,0));
      cam.lookAt(CarFront.getLocalTranslation(), new Vector3f(0,0,0));
   }



I'm desperate for help! I cant fix this!

All I want is so the camera is looking at the cam from behind, No mather if it flips over!
How?!

Well, I'm not sure how the lookAt method works exactly, but it seems you're setting your up vector to (0,0,0).

I'm not sure how I would interpret this, but in any case that is a vector of length 0, so I don't think the method will know what you mean by "up" with this. Try a non-zero vector (like (0,1,0) or which ever direction you want to be up).

Other than the lookAt method I don't see you setting the rotation of your cam node anywhere. Perhaps lookAt uses a local coordinate system for it's rotation and as it's attached to your vehicle (I assume) it's coordinate system is relative to your vehicle's coordinate system?



As it seems you've got a cam node attached to your vehicle it will rotate with it as well, so you will need to either have an independant cam node or camera or set your cam node's rotation to what you want it to be.

I don't know how you rotate your vehicle, but you can use setLocalRotation to set the rotation of your cam node to what you want it to be. Perhaps you could try setting it to the opposite of what you set your vehicle to be for the axis that the vehicle flips on? Or always set it to the opposite of the angle between an up vector and the vehicle's rotation? Or you could perhaps use a chase camera on an independent node and set that to a specific rotation for some axes? I've had problems with the chase camera class in jme, but you can make your own chase camera if you have specific needs that the jme one can't do.



Perhaps one of those guesses can help!

Good luck!

I think that the problem is most likely that your camera node is a child of your car node – meaning that the camera node is going to move and rotate along with the car node.  To get a camera that follows the car but does not rotate/flip with the car you will have to separate the nodes while somehow preserving the "chase" but not the rotational behavior.  You can probably do this with a separate camera node that updates its position based on the car's local translation and heading/direction and whatever you want as its distance from the car.