I have a GLTF model with objects within that are clickable, when the user clicks the object the camera zooms in to focus on the object. Currently I have an ‘if’ statement so when users click anywhere apart from the zoomed object, the camera position changes back to ‘x:12, y:8, x:8’ which is the starting value. The problem is if the user has zoomed in or out with the mouse wheel, these values would have changed, so when the camera zooms out from an object it is in a different position to what it was before zooming into the object.
I need a better way of doing this by somehow saving the camera position when the user clicks to zoom in on an object, then when they click outside the object to zoom out, the camera zooms out to the saved position.
I have created a working Codpen that is collaborative and can be edited and saved, please let me know if you are able to help. You can also leave comments directly on the codepen in the bottom right corner.
The front left and back left trees are the clickable objects.