Jittery Camera movement

I'm developing a good old space Shoot Em Up of the old school (view from straight above, movement only in 2 directions, but with jME as engine). Having a bit of a problem with camera movement, it keeps jittering back and forth.

Basically, I want the camera to be placed above the player's ship, looking straight down with a fixed rotation ("north" in the game-world should be up on the screen). Preferably, I want the camera to be placed slightly "infront" of the ship, so that the ship is moved towards the edge of the window when flying forward.

Right now I have just a single Camera whose position I refresh in update(). I've tried various variants to refresh the position, but all with basically the same jittering. When attaching the Camera to a CameraNode and attaching that to the player's ship Node, the camera was moving and rotating smoothly, but ofcourse the view also rotated with the ship which is not what I want. Tried applying a local rotation to the camera node to oppose the ship's rotation - movement of camera was still smooth, but rotation caused jittering.

I'm figuring I'm just doing something wrong with the update, so the camera is moved unsync'ed with the frame rendering somehow, but not at all certain. I've been trying to replicate (part of) the camera code from Furballz, but to no avail.

Any help would be much appreciated!

Here's my current code, placed in update(). (camPos and viewPos are both Vector3f declared as class members):

Vector3f targetPos = new Vector3f(ent.getModel().getWorldTranslation());
targetPos.x += Math.cos(ent.getDir() - FastMath.HALF_PI) * ent.getSpeed().length();
targetPos.y += Math.sin(ent.getDir() - FastMath.HALF_PI) * ent.getSpeed().length();
if (camPos == null) {
   camPos = new Vector3f(targetPos.x, targetPos.y, 250);

camPos.x += (targetPos.x - camPos.x) * 0.1f;
camPos.y += (targetPos.y - camPos.y) * 0.1f;
camPos.z = 250;
viewPos.x = camPos.x;
viewPos.y = camPos.y;
viewPos.z = 0;


You use tthe worldTranslation before it is updated. Calling updateWorldVectors() before updating the camera should help (it is already called somewhere depending on the Superclass you use for your game).

Another thing you could do in this case is making a playerNode that contains the ship and a camera node. Then rotate the ship but move the playerNode.

That helped alot! Thank you!

This thing is multiplayer (client - server based), so I'm looking to make as little difference between the "player" and "every other entity". Feels more OO that way anyways. :slight_smile: