ChaseCam follows a Spatial moving block by block smoothly

I have a Box Spatial and a ChaseCam following the Spatial. But my problem is the Spatial is moving block by block (it is supposed to do it) and because it is moving block by block The CahseCam is glitching as I suppose.

My question is, is there a handy way to make the camera follow the Spatial smoothly, while the Spatial moves block by block?

My CamInit:
public class CamInit {

private final InputManager inputManager;
private final Camera cam;
public static ChaseCamera chaseCam;
private final FlyByCamera flyCam;

@SuppressWarnings("static-access")
public CamInit(AppSettings settings, InputManager inputManager, Camera cam, FlyByCamera flyCam) {
	assert (inputManager != null);
	this.inputManager = inputManager;
	assert (cam != null);
	this.cam = cam;
	assert (flyCam != null);
	this.flyCam = flyCam;
	this.chaseCam = new ChaseCamera(this.cam, SnakeInit.snake[0], this.inputManager);
	
	//this.cam.setFrustumPerspective(116.0f, (settings.getWidth() / settings.getHeight()), 1.0f, 2000.0f);		
	this.flyCam.setEnabled(false);
	chaseCam.setDefaultDistance(1.5f);
	chaseCam.setMaxDistance(2.5f);
	chaseCam.setMinDistance(1.5f);
	chaseCam.setDefaultVerticalRotation(40 * FastMath.DEG_TO_RAD);
	chaseCam.setDefaultHorizontalRotation(FastMath.PI);
	chaseCam.setSmoothMotion(true);
	chaseCam.setTrailingEnabled(true);
	chaseCam.setChasingSensitivity(100);
	chaseCam.setTrailingSensitivity(500);
	chaseCam.setTrailingRotationInertia(0.1f);
	//chaseCam.setDragToRotate(false);
	chaseCam.setEnabled(true);
}

}

Video of the glitching ChaseCam:

https://youtu.be/JUcYEQax1Q8

Try to do something along the lines of making the cam move half way the distance from its current location to the desired location of the cam and multiply that by the time per frame(tpf).This should give the desired effect and then you can multiply the tpf with a float to polish the feel of the motion.

Well, when using setSmoothMotion(true) the ChaseCamera should interpolate towards the new position and not just jump. However I think that setting really high values on chasingSensitivity and trailingSenstivity might cause really fast movement of the camera making it look like it’s jumping from position A to B really fast. Have you tried using the default values?

Just wondering couldn’t you just move the camera without the control? this seems like it is a basic enough camera?

float camDistance = 10f;
float camHeight = 8f;
float camMoveSpeed = 2f;

Vector3f camLocation = cam.getLocation();
Vector3f newCamLocation = target.subtract(camLocation);
newCamLocation.setY(0);
newCamLocation.normalizeLocal();
newCamLocation.multLocal(camDistance);
newCamLocation.setY(camHeight);
newCamLocation.addLocal(target);
camLocation.interpolate(newCamLocation, camMoveSpeed * tpf);
cam.setLocation(camLocation);
cam.lookAt(target, Vector3f.UNIT_Y);

I’ve tried it, but it didn’t made a difference! It was just the same

I’m using the ChaseCamera, I don’t set the Camera position anywhere it just follow’s the cube at the front as I declared it!

I thought using a ChaseCamera is more simple than having to write a camera which position you have to set every tick.

But if there is definitly no other way to to this, I’ll follow your idea.

I am not saying there is no other way just this is an option and it is simple enough to implement. you could even wrap the code I posted in a custom control.

Now don’t take this word for word just as an example, I am missing some getters and setters, but wrapping this up might be faster and easer.

public class MyCameraControl extends AbstractControl {
	
	private float cameraDistance = 10f;
	private float cameraHeight = 8f;
	private float cameraMoveSpeed = 2f;
	
	private Camera camera;
	private Vector3f cameraLocation;
	private Vector3f newCameraLocation;
	
	public MyCameraControl() {
		cameraLocation = new Vector3f();
		newCameraLocation = new Vector3f();
	}
	
	public MyCameraControl(Camera camera) {
		this.camera = camera;
		cameraLocation = new Vector3f();
		newCameraLocation = new Vector3f();
	}
	
	public Camera getCamera() {
		return camera;
	}
	
	public void setCamera(Camera camera) {
		this.camera = camera;
	}
	
	@Override
	public void setSpatial(Spatial spatial) {
		super.setSpatial(spatial);
	}
	
	@Override
	protected void controlUpdate(float tpf) {
		if(spatial != null && camera != null) {
			Vector3f spatialLocation = spatial.getWorldTranslation();
			cameraLocation.set(camera.getLocation());
			newCameraLocation.set(spatialLocation.subtract(camLocation));
			newCamLocation.setY(0);
			newCamLocation.normalizeLocal();
			newCamLocation.multLocal(cameraDistance);
			newCamLocation.setY(cameraHeight);
			newCamLocation.addLocal(spatialLocation);
			camLocation.interpolate(newCamLocation, cameraMoveSpeed * tpf);
			camera.setLocation(camLocation);
			camera.lookAt(spatialLocation, Vector3f.UNIT_Y);
		}
	}
	
	@Override
	protected void controlRender(RenderManager renderManager, ViewPort viewPort) {
	}
}

and your code to use it would look like this.

SnakeInit.snake[0].addControl(new MyCameraControl(cam));