I want to restrict the camera z position to a value.
For that i’m updating the camera position in render function as below.
camera.position.z = 5;
I’m able to restrict it but when i’m using the orbit controls the rotations are not working correctly.
Any help would be appreciated
no need to manually restrict the camera position when using
OrbitControls, the class has a maxDistance method to do exactly that…
controls.maxDistance = 5
should do what you’re looking for.
Thanks for your reply
If i set the maxDistance to some value it means camera can go till that max value, Right?
But in my case i want to set the camera to certain value all the time.
Let me know if I’m missing something here.
Any chance you can elaborate on what you mean by this, it’s tricky to understand what your trying to achieve… Eg. Why would you need orbit controls if you want the camera fixed?
If you set
minPolarAngle to the same value, the camera cannot go up or down, but can still orbit horizontally around the target.
Alternatively, if you set
minAzimuthAngle to the same value, the camera will be horizontally fixed, but can orbit vertically.
In any case, when you use
OrbitControls it is a bad idea to control the camera manually, because
OrbitControls will try to overpower you and your changes.
Thanks for the help guys.
I’m able to solve the issue.