# Perspective camera limit zooming not working properly

**URL:** <https://discourse.threejs.org/t/perspective-camera-limit-zooming-not-working-properly/37605>\
**Category:** Questions\
**Tags:** perspective-camera, camera-controls, camera\
**Created:** [April 29, 2022, 4:10am UTC](https://discourse.threejs.org/t/perspective-camera-limit-zooming-not-working-properly/37605 "2022-04-29T04:10:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanjil\_Hossain](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/tanjil_hossain/32/25460_2.png) [@Tanjil\_Hossain](https://discourse.threejs.org/u/Tanjil_Hossain)\
**Post date:** [April 29, 2022, 4:10am UTC](https://discourse.threejs.org/t/perspective-camera-limit-zooming-not-working-properly/37605/1 "2022-04-29T04:10:40Z")

</div>

I’m trying to limit the zoom when a button is off. When it is off limit the zoom and when it is on there is not limit for zooming.It should work as it is. limit is working when the button is off but when it is on it is not reseting the limit.  
I’m using this code:

```javascript
  useEffect(()=>{
    if(!props.keyplanOpen || !props.unitOpen || !props.miscOpen){
      controls.minDistance=100
      controls.maxDistance=300 
      
    }else{
      controls.minDistance=0
      controls.maxDistance=0
    }
  },[props.unitOpen,props.keyplanOpen,props.miscOpen])

```

I’m using perspective camera with orbitcontrols in react three fiber. Thanks

---

<div class="post-metadata">

**Author:** ![vielzutun.ch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/vielzutun.ch/32/21366_2.png) [@vielzutun.ch](https://discourse.threejs.org/u/vielzutun.ch)\
**Post date:** [April 29, 2022, 7:46am UTC](https://discourse.threejs.org/t/perspective-camera-limit-zooming-not-working-properly/37605/2 "2022-04-29T07:46:04Z")

</div>

Have you tried [`controls.update();`](https://threejs.org/docs/#examples/en/controls/OrbitControls.update)  
after a controls property change?

---

<div class="post-metadata">

**Author:** ![Tanjil\_Hossain](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/tanjil_hossain/32/25460_2.png) [@Tanjil\_Hossain](https://discourse.threejs.org/u/Tanjil_Hossain)\
**Post date:** [April 29, 2022, 9:59am UTC](https://discourse.threejs.org/t/perspective-camera-limit-zooming-not-working-properly/37605/3 "2022-04-29T09:59:31Z")

</div>

tried that. Not working. It is still set to minDistance=100, maxDistance=100. What I want is if any of this button is off then limit the zoom. That is limiting the zoom but its not being reset when the button is on.

---

<div class="post-metadata">

**Author:** ![JuanP](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/juanp/32/25869_2.png) [@JuanP](https://discourse.threejs.org/u/JuanP)\
**Post date:** [April 29, 2022, 1:03pm UTC](https://discourse.threejs.org/t/perspective-camera-limit-zooming-not-working-properly/37605/4 "2022-04-29T13:03:43Z")

</div>

@Tanjil_Hossain with min and max distance you limit the dolly of the camera not the zoom. If you indeed are talking about zoom and is not a confusion of concepts you should use `maxZoom` and `minZoom` assuming you are using an orthographic and not a perspective one.

If you are using a perspective camera I bet your conditional is the one failing or you never reach that piece of code. Log everything to check it:

```javascript
useEffect(()=>{
    console.log('useEffectEnter');
    console.log(props.keyplanOpen, props.unitOpen, props.miscOpen);
    if(!props.keyplanOpen || !props.unitOpen || !props.miscOpen){
      console.log('Limit camera distances');
      controls.minDistance=100
      controls.maxDistance=300 
      console.log(controls);
    }else{
      controls.minDistance=0
      controls.maxDistance=0
    }
  },[props.unitOpen,props.keyplanOpen,props.miscOpen])
```

---

<div class="post-metadata">

**Author:** ![Tanjil\_Hossain](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/tanjil_hossain/32/25460_2.png) [@Tanjil\_Hossain](https://discourse.threejs.org/u/Tanjil_Hossain)\
**Post date:** [April 30, 2022, 5:50am UTC](https://discourse.threejs.org/t/perspective-camera-limit-zooming-not-working-properly/37605/5 "2022-04-30T05:50:03Z")

</div>

Basically, I’m trying to limit the scrolling effect on the model. When I’m scrolling the mouse wheel it’s going inside of the model and scrolling out at a certain time shows the whole area that I don’t want.  
What I want is to limit the scrolling effect. It should stay out of the building and not go inside of the building as well as zooming or dolly whatever you say should be in a limit. you can see in the video

[https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/4/9/49fdb24781bd1935d07aac9d76c72d8d7fc8566f.mp4](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/4/9/49fdb24781bd1935d07aac9d76c72d8d7fc8566f.mp4)
