Why my camera is shaking?

Why my camera is shaking?

[java]import com.jme3.renderer.RenderManager;

import com.jme3.system.AppSettings;

import com.jme3.app.SimpleApplication;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.collision.shapes.CollisionShape;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.material.Material;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.bullet.BulletAppState;

import com.jme3.scene.Node;

import com.jme3.bullet.control.CharacterControl;

import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;

import com.jme3.input.KeyInput;

import com.jme3.input.MouseInput;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.AnalogListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.input.controls.MouseButtonTrigger;

import com.jme3.scene.Spatial;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Quaternion;

import com.jme3.scene.shape.Box;


  • test
  • @author normenhansen


    public class Main extends SimpleApplication {

    public static void main(String[] args) {

    Main app = new Main();

    AppSettings settings=new AppSettings(true);





    Boolean isRunning=true;

    float acel=0;

    private RigidBodyControl landscape;

    private RigidBodyControl landscape2;

    float x=0;

    Vector3f posoka;

    Spatial korab;

    private RigidBodyControl korab_phy;

    private RigidBodyControl stancia_phy;

    Spatial stancia;

    Geometry blue;

    Geometry red ;

    Boolean gf=false;

    private CharacterControl player;

    Geometry korab_geo;

    Geometry stancia_geo;

    private BulletAppState bulletAppState;

    public void simpleInitApp() {




    // rootNode.attachChild(korab);

    // rootNode.attachChild(stancia);

    Node pivot = new Node("pivot");







    private void initphysics()


    bulletAppState = new BulletAppState();


    CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);

    player = new CharacterControl(capsuleShape, 0.05f);

    player.setPhysicsLocation(new Vector3f(0, 0, -1000));




    // CollisionShape sceneShape3 = CollisionShapeFactory.createMeshShape((Node) korab);

    CollisionShape sceneShape =CollisionShapeFactory.createMeshShape( stancia);

    CollisionShape sceneShape2 =CollisionShapeFactory.createMeshShape( korab);

    stancia_phy=new RigidBodyControl(sceneShape,0);

    korab_phy=new RigidBodyControl(3f);







    // korab_phy.setLinearVelocity(new Vector3f(0,0,1000));


    private void initcammera()


    cam.lookAt(new Vector3f(1,3,1), new Vector3f(10,30,20));


    private void initobjects()


    Box box1 = new Box( new Vector3f(1,-1,1), 1,1,1);

    blue = new Geometry("Box", box1);

    Material mat1 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");

    mat1.setColor("Color", ColorRGBA.Blue);


    Box box2 = new Box( new Vector3f(1,3,1), 1,1,1);

    red = new Geometry("Box", box2);

    Material mat2 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");

    mat2.setColor("Color", ColorRGBA.Red);


    korab = assetManager.loadModel("Models/KORAB.obj");

    korab_geo= (Geometry) korab;

    stancia = assetManager.loadModel("Models/Space.obj");

    Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");



    stancia.setLocalRotation(new Quaternion(4f,0.5f,0.6f,1));

    stancia.setLocalTranslation(0, 0, -1000);

    stancia_geo=(Geometry) stancia;


    private void initKeys() {

    inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P));

    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J));

    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K));

    inputManager.addMapping("Acel", new KeyTrigger(KeyInput.KEY_R));

    inputManager.addMapping("DEC", new KeyTrigger(KeyInput.KEY_F));

    inputManager.addMapping("Rotate", new KeyTrigger(KeyInput.KEY_SPACE),new MouseButtonTrigger(MouseInput.BUTTON_LEFT));

    inputManager.addListener(actionListener, new String[]{"Pause"});

    inputManager.addListener(analogListener, new String[]{"Left", "Right", "Rotate","DEC","Acel"});


    private ActionListener actionListener = new ActionListener() {

    public void onAction(String name, boolean keyPressed, float tpf) {

    if (name.equals("Pause") && !keyPressed) {

    isRunning = !isRunning;




    private AnalogListener analogListener = new AnalogListener() {

    public void onAnalog(String name, float value, float tpf) {

    if (name.equals("Rotate")) {

    korab.rotate(0, value
    speed, 0);


    if (name.equals("Acel")) {



    if (name.equals("DEC")) {



    if (name.equals("Right")) {

    Vector3f v = korab.getLocalTranslation();

    korab.setLocalTranslation(v.x + valuespeed, v.y, v.z);


    if (name.equals("Left")) {

    Vector3f v = korab.getLocalTranslation();

    korab.setLocalTranslation(v.x - value
    speed, v.y, v.z);




    public void simpleUpdate(float tpf) {

    x=tpfacel0.1f + x;

    korab_phy.setLinearVelocity(new Vector3f(0,0,x));


    cam.setLocation(new Vector3f(0f,4f,posoka.getZ()+14f));

    cam.lookAt(korab_geo.getLocalTranslation(), new Vector3f(0,0,0));



    public void simpleRender(RenderManager rm) {



what do you mean shaking? maybe record a video.

[java]cam.lookAt(korab_geo.getLocalTranslation(), new Vector3f(0,0,0));[/java]

your up vector looks a bit odd, try Vector3f.UNIT_Y

It is glitching.One moment is a little bit ahead and in the other behind.

Because the physics are running with 60hz in another thread, therefore decoupled from your render thread which runs with your fps.

The problem is here:


x=tpfacel0.1f + x;


Every frame you set a velocity that is frame-dependent but use that in the physics thread. NEVER use tpf for physical forces etc.

Just write


x += acel*0.1f


Again is glitching.

Glitching often occurs when floating point numbers are really long due to precision loss.

What kind of coordinates that cam is at or the object it’s looking at is? Anything higher than 15 000 will start giving noticeable jumping around on the screen.

whell from 0 to 1000.

That won’t be problematic. The problem is somewhere else.

A video would really help though. Just saying.

To me it looks more like the model is going into a freespin than the camera going crazy… Physics maybe?

i suppose this is chasecam parameter. I dont remember how it’s called. Like “chasecam.smoothFollow(true)”. Just make it false.

What you do with the linearvelocity there is not correct, you set it each frame, basically messing up all physics computations concerning it. If you just want to move your ship you don’t need physics. If you use physics you need to use forces, the setLinearVelocity only makes sense when you “spawn” an object with a certain velocity in your game world or you do physics syncing.

Ok.And how to move the ship ?

Just set its location? Or as said if you use physics then use forces.

Ок.Here is the problem.I want to move the ship.And I want the ship to collide with the station.For now there is collisions.

So you will have to check for collisions or move the ship by applying forces.

And how to apply forces?

By using the appropriate methods on the physics objects. Listen, nobody here is interested in writing your game, you will have to do the tutorials yourself to be able to do this. Its all explained.

In the tuts they use setLinearVelocity.

Its used for the “projectiles” which is valid as I indicated before. Just copy-pasting one out of context line isn’t what I mean by “doing the tutorials” I am afraid.