Hi, I am using Perspective Camera and Orbitcontrols in my Scene. On user inputs, I need to change the camera position from one place to another. at that time, the scene gets flickering. But I need the screen should get off and on smoothly, when the screen gets on, the camera position should be at the changed position. Is it possible , how to do that. If my question is difficult to understand, please ask.
Since Camera.position is just a Vector3, you can use Vector3.lerp to transition to another position smoothly (alpha argument determines how fast the value will transition to another one.)
Mind, the scene is probably flickering because you are changing camera.position when using OrbitControls. Change controls.target instead - otherwise both you and OrbitControls try to set camera position to different values within one frame.
yes @mjurczyk . I am setting the position of camera and the orbitcontrols’s target too. If I am wrong, then how to achieve that. Because, the camera position decides where should the camera be placed. And the Orbitcontrols target only decides, where the camera should see. But you are saying, we shouldn’t do both changes. Then How to change the camera position and where should it see?
If you are altering both camera and control target positions - try synchronising them to avoid jumpy frames:
const oldTargetPosition = controls.target.clone();
controls.target = someNewTarget;
const dPosition = oldTargetPosition.sub(controls.target);
camera.position.sub(dPosition); // Camera is moved in the same direction and by the same offset, so angle between viewer and target will remain the same.
Thank you so much for your suggestions @mjurczyk . I have used this controls.update() statement within animate loop @prisoner849 . So I think, no need to call it whenever the changes occured. And One more thing is, can anyone please share an example for tweening the camera to a position with jsfiddle or any codepen ?
@prisoner849. I have done my requirement with your suggestion of tweening examples. But the camera is moving through inside of the object. Any ways to avoid this? And I am getting some lagging also while camera movement. Please help me to avoid these two issues