drei icon indicating copy to clipboard operation
drei copied to clipboard

Handling boundary box for camera to prevent movement outside

Open hansyulian opened this issue 1 year ago • 0 comments

What is your question:

So I would like to make the camera movement smooth in this example of bounding the camera position to the box:

https://github.com/hansyulian/questions/tree/main/question-2024-01-04-camera-boundary

I figured out the problem is because the camera move before i check the validity of the position and thus after i found out that the camera is moving out of the box, i just throw it back inside the box based on the closest point to the box. this causes the jaggy camera movement which is not nice.

i would like to find is there a way for either:

  • hook on the camera's new position before it's moved, something like onBeforeCameraPositionChange(before, after)
  • smooth out the throw back, preventing the jaggy camera movement?
  • any better solution than what i have?

hansyulian avatar Jan 04 '24 04:01 hansyulian