ChaseCamera bouncing around problem

havent posted a question for a while, but im back now  :wink:



im having problems with my chase camera. it always bounces around like crazy for about 5 to 10 seconds before it starts following the target.



i created a ChaseCamera as the following :


      this.chaseCam = new ChaseCamera(this.game.getCamera(), this.player);
      this.chaseCam.setMaintainAzimuth(true);
      this.chaseCam.getMouseLook().setLookMouseButton(2);
      this.chaseCam.setStayBehindTarget(true);
      Vector3f targetOffset = new Vector3f(0,0,0);
      targetOffset.setY(((BoundingBox)this.player.getWorldBound()).yExtent*0.2f);
      this.chaseCam.setTargetOffset(targetOffset);
      this.chaseCam.setActionSpeed(0.2f);
      this.chaseCam.getMouseLook().setMaxAscent(50 * FastMath.DEG_TO_RAD);
      this.chaseCam.getMouseLook().setMinAscent(-30 * FastMath.DEG_TO_RAD);
      this.chaseCam.getMouseLook().setMaxRollOut(20);
      this.chaseCam.getMouseLook().setMinRollOut(5);
      this.chaseCam.getMouseLook().setMouseRollMultiplier(4);
      this.chaseCam.setIdealSphereCoords(new Vector3f(12, 0, 40*FastMath.DEG_TO_RAD));



and my chase camera always bounces around for like 5 to 10 seconds before it stablizes. and heres the output for the camera position and player position.


Camera: com.jme.math.Vector3f [X=-2261.2964, Y=-15502.939, Z=1230.618]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-2137.229, Y=-14653.564, Z=1163.1353]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-2025.1649, Y=-13886.365, Z=1102.1813]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1917.8201, Y=-13151.475, Z=1043.7942]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1816.6418, Y=-12458.801, Z=988.7612]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1712.1166, Y=-11743.213, Z=931.9078]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1618.2233, Y=-11100.412, Z=880.8373]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1530.985, Y=-10503.172, Z=833.3866]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1451.3407, Y=-9957.921, Z=790.06647]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1376.1936, Y=-9443.458, Z=749.19244]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1305.083, Y=-8956.63, Z=710.514]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1233.6729, Y=-8467.75, Z=671.67255]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1165.6307, Y=-8001.9287, Z=634.6631]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1102.9017, Y=-7572.4814, Z=600.5435]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-1044.1174, Y=-7170.0396, Z=568.5695]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-988.57336, Y=-6789.781, Z=538.358]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-936.2199, Y=-6431.365, Z=509.88184]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-887.8933, Y=-6100.5176, Z=483.596]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-841.9019, Y=-5785.657, Z=458.58035]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-797.44354, Y=-5481.292, Z=434.39853]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-755.0787, Y=-5191.259, Z=411.3554]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-715.45245, Y=-4919.9746, Z=389.80188]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-676.4895, Y=-4653.2314, Z=368.60913]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-639.1509, Y=-4397.6084, Z=348.2999]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-604.0183, Y=-4157.0884, Z=329.19058]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-571.03577, Y=-3931.2876, Z=311.2507]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-539.11334, Y=-3712.7444, Z=293.88745]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-509.24252, Y=-3508.2463, Z=277.6401]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-479.80157, Y=-3306.6914, Z=261.62656]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-452.23102, Y=-3117.9414, Z=246.63037]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-424.97006, Y=-2931.3108, Z=231.80257]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-400.2, Y=-2761.7332, Z=218.32962]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-376.6768, Y=-2600.6914, Z=205.53485]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-354.19278, Y=-2446.7642, Z=193.30533]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-332.6283, Y=-2299.132, Z=181.57596]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-312.11548, Y=-2158.6997, Z=170.41861]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-292.27643, Y=-2022.88, Z=159.62773]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-273.62524, Y=-1895.1926, Z=149.48297]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-256.1305, Y=-1775.4221, Z=139.96721]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-238.2083, Y=-1652.7255, Z=130.21896]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-221.73296, Y=-1539.934, Z=121.25768]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-205.2112, Y=-1426.8247, Z=112.271164]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-189.91014, Y=-1322.0725, Z=103.94861]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-175.9948, Y=-1226.807, Z=96.37977]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-162.69537, Y=-1135.7582, Z=89.14594]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-150.06734, Y=-1049.3057, Z=82.27729]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-138.4553, Y=-969.8088, Z=75.961266]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-127.08586, Y=-891.97266, Z=69.77719]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-114.59832, Y=-806.482, Z=62.984962]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-103.30852, Y=-729.19116, Z=56.844208]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-92.21825, Y=-653.26636, Z=50.811985]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-81.35481, Y=-578.8945, Z=44.90314]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-70.767975, Y=-506.41617, Z=39.144745]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-61.015594, Y=-439.6506, Z=33.840225]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-51.945515, Y=-377.55612, Z=28.906822]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-43.44614, Y=-319.36874, Z=24.283838]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-35.78737, Y=-266.9362, Z=20.118074]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-28.847275, Y=-219.42377, Z=16.343214]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-22.745102, Y=-177.64781, Z=13.0241165]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-17.445606, Y=-141.36705, Z=10.141612]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-12.865675, Y=-110.012474, Z=7.650493]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-8.969607, Y=-83.33969, Z=5.5313416]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-5.6596165, Y=-60.67923, Z=3.7309694]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-2.8707237, Y=-41.58625, Z=2.2140336]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=-0.52182126, Y=-25.50548, Z=0.93641734]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=1.458764, Y=-11.946236, Z=-0.14086366]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=3.1079986, Y=-0.65544415, Z=-1.0379163]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=4.484598, Y=8.768866, Z=-1.7866769]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=5.5963755, Y=16.38018, Z=-2.3913953]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=6.492377, Y=22.514275, Z=-2.8787487]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=7.224037, Y=27.523281, Z=-3.2767138]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]
Camera: com.jme.math.Vector3f [X=7.816224, Y=31.577438, Z=-3.5988164]
Player: com.jme.math.Vector3f [X=0.0, Y=55.022495, Z=-5.0]



im only posting a portion of the output so i dont make this page too long to be readable.

but anyways, as u can c, the camera bounces around like crazy for a while before it stablizes. whats the problem here?

There is a setDampingK method for the spring simulation on the chase camera.  Try setting it with a higher value (maybe 30?).  Play around with it until you get the desired result.  I think that will get it, but if not, post back.


gtzpower said:

There is a setDampingK method for the spring simulation on the chase camera.  Try setting it with a higher value (maybe 30?).  Play around with it until you get the desired result.  I think that will get it, but if not, post back.




i understand that this might allow me to work around the problem since it restrains the camera's movement. but i dont think this solves the problem since the question of y the camera bounces in the first place is not answered.

i did put the camera at excatly where the target is, and that still does not prevent the camera from bouncing around. technically, if the camera is already at the ideal position, then it should only need to move a little to adjust its position instead of bouncing to 10000+.

and even with the added spring constant and damping constant, the camera still bounces. its just that is comes back much mode quickly than before.

I just tried your code in a sample app of mine, and it worked (I changed some variables around to plug it in), here's what it looks like:

       this.chaseCam = new ChaseCamera(cam, this.ball);
      this.chaseCam.setMaintainAzimuth(true);
      this.chaseCam.getMouseLook().setLookMouseButton(2);
      this.chaseCam.setStayBehindTarget(true);
      //Vector3f targetOffset = new Vector3f(0,0,0);
      targetOffset.setY(((BoundingSphere)this.ball.getWorldBound()).radius*0.2f);
      this.chaseCam.setTargetOffset(targetOffset);
      this.chaseCam.setActionSpeed(0.2f);
      this.chaseCam.getMouseLook().setMaxAscent(50 * FastMath.DEG_TO_RAD);
      this.chaseCam.getMouseLook().setMinAscent(-30 * FastMath.DEG_TO_RAD);
      this.chaseCam.getMouseLook().setMaxRollOut(20);
      this.chaseCam.getMouseLook().setMinRollOut(5);
      this.chaseCam.getMouseLook().setMouseRollMultiplier(4);
      this.chaseCam.setIdealSphereCoords(new Vector3f(12, 0, 40*FastMath.DEG_TO_RAD));



in my initSystem method, I call the following to get my camera:

cam = display.getRenderer().createCamera( display.getWidth(), display.getHeight() );


Can you post the entire class so I can try running it to recreate the issue?

I'm experiencing the same thing when i use chasecam.setIdealLocation(player.getlocalTranslation().clone())

setting the cam location directly doesn't seem to have any effect .

Placing the cam at in systemInit()  at the player location will result in a smooth transition to the player. however using some other location for this will result in a black picture only showing the fps node with the message nothing to display

gtzpower said:

cam = display.getRenderer().createCamera( display.getWidth(), display.getHeight() );


Can you post the entire class so I can try running it to recreate the issue?


thx for the help but i cant post the entire class since i have about 30 classes or so. the one related to the chase camera is only this portion. and the camera creation is obviously in the initSystem method with the display's width and height. i dont c any other options.


setting the cam location directly doesn't seem to have any effect .
Placing the cam at in systemInit()  at the player location will result in a smooth transition to the player.


thats very interesting, ill try it out and if it is true then theres definitely something fishy going on with the chase camera

After playing around with this problem I've found out where it originates from:

The javadoc of the update function says:


The springK and dampingK factors can be expressed as a damping ratio:

ratio = dampingK / (2 * sqrt(springK))

Typically you want the ratio to come out equal to 1. Values less than 1 will oscillate before coming to rest. Values over 1 will take longer than necessary to come to equilibrium.


The ratio value is correctly 1.0 when values for dampingK and springK aren't changed.
Nevertheless, the chase camera can bounce when the timePerFrame value is too high.
This often happens at the beginning of the render process. I've tested it with manually setting the tpf and it worked up to a value of about 0.135 on my computer. I don't know the exact reason for that, but these few lines at least fix it:

protected boolean firstFrame = true;

protected final void update(float interpolation) {
...
    if (firstFrame) {
        timer.reset();
        firstFrame = false;
    }
...
}