Fixed chase camera

I'm sure this is more simple than I think it is, but I've been playing with ChaseCamera for ages without much success.

I'm trying to make a camera that follows an object and rotates when the object rotates. I want to use the keyboard for input but have the mouse input ignored so I can use the mouse for something else.

Is there an easy way to do this with ChaseCamera or is it easier to do by creating a custom camera? Can anyone point me in a direction that would help please?

Depending on what you need to do with the mouse, it may be easier to just take the parts out of ChaseCamera that you need, and create you own controls.

to disable mouse control over chase camera use chaseCamera.getMouseLook().setEnabled(false);

to make it rotate as the model rotates use the setBehindTarget(true);

Thanx Neakor, I will need that info very soon :slight_smile:

Here’s what I’m trying to do (T is the target object, C is the camera and O is the origin):

The first image shows the Target rotated by 90 degrees and a bit forward and left of the Origin. The Camera is offset from the Origin because I want it to eventually be offset from the Target.

The second image is the Camera rotated by the same amount that the Target is rotated (i.e. 90 degrees). It still looks at the Target but is now in a different position relative to the Origin due to the rotation.

The third image shows the Camera moving by the Target’s location relative to the Origin and looks at the Target again so is effectively behind the Target by the offset amount.

Here’s the code that I’m hoping will do it (but doesn’t)

package core;

import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.scene.Spatial;

public class FollowCamera {
   private Vector3f worldUpVector = Vector3f.UNIT_Y.clone();
   private float height;
   private Spatial target;
   private Camera camera;
   private Vector3f cameraOffset;
   public FollowCamera(Camera camera, float height, Spatial target) { = camera;
      this.height = height; = target;
      cameraOffset = new Vector3f(0, 40, 40);
    * Update the camera's position and view
    * @param time
   public void update(float time) {
      // Rotate camera to have same orientation as target
      Vector3f newPos = target.getLocalRotation().mult(cameraOffset);
      // Move camera to target
      // Make the camera a set height above the target
      newPos.y = target.getLocalTranslation().y + height;
      // Look at target
      camera.lookAt(target.getLocalTranslation(), worldUpVector);

All the camera does is wobble a little towards and away from the target but always looks at it. Is my idea of how it should work sensible? I know my implementation is incorrect. Can anyone help me please?

Well, you could probably use a TimedLifeController and just have it move the camera a little bit each update, multiple updates for different movements.  You would have to trigger when this happens each time, so if you are wanting a more automated approach you would have to devise a way to logically trigger this.