how to prevent to through a wall or shape?

I want to stop at cube suface while I am zooming. I dont want to go through the cube like a walking through a wall. Can you tell what is best possible solution for this. Thank you in advance.

You need collision detection for this feature.

Your simplest approach is to define a sphere with a diameter equal to cube side, and then a sphere of the size of the viewer avatar(ie imaginery viewer). Then check to see if the two spheres intersect. Google for this topic, there are way too many issues to cover in thread, and plenty of source code to show you how to do it online.