[SOLVED] what is wrong with this change camera.pan code?

Posted By: Reconnoiter

[SOLVED] what is wrong with this change camera.pan code? - 08/18/15 11:45

Hi,

I use the following code when smoothly zooming in to the front of entities, but sometimes the camera shakes heavily when it is near its chosen/designated pan (/angle). It has seems to shake when the pan/angle of the target has decimals (/not a nice integer number).

This is e.g. with a fps of 50-60;

Code:
function cam_focusonentity()
{
  while(...)
  {
  ...

  //change pan angle
  if (1 < abs(target_ent.pan+180-camera.pan)) camera.pan += 4 * time_step * sign(ang(target_ent.pan-180 - camera.pan));
  
  ...
  wait(1);
  }
}



The code line is a bit long, but it was the only way I knew how to make it that the angle is changed evenly and always reached its target.

So anyone know how to prevent it from shaking?

[FOR SOLUTION SEE MY 2ND POST]
Posted By: 41Lumber

Re: what is wrong with this change camera.pan code? - 08/18/15 16:44

Try this (full line) instead:

Code:
camera.pan += ang(target_ent.pan+180 - camera.pan) * minv(1, 4 * time_step);



The minv call is there so that if your frame rate dips below 16fps (time_step = 1), it won't overshoot and cause a violent shaking effect. Tweak the 4 if the rotation is not smooth enough for your liking (smaller number = more smoothing).
Posted By: Reconnoiter

Re: what is wrong with this change camera.pan code? - 08/18/15 18:00

Hi 41Lumber,

Thanks for replying.
The problem with that code line is that in the beginning it goes to fast (disorientating) and at the end it goes to slow resulting in that it doesn't always finish to the end.

I found a solution though. I added a few lines to check when the sign() of camera.pan increasement suddenly changes, if so I stop the change pan code. It works really nice so far.

Anyway thanks for your time.
© 2024 lite-C Forums