Rendering a 3D object within a specific area/bound?

Hello, I’m trying to recreate the “Examine” feature in Resident Evil Remake.
Currently, I have the rotation right, what’s left is how to setup a background, and handle the camera(s) responsible for that. (By background I mean the image behind the object)

FYI I’m using NGUI. I have no problem setting up a background, with a separate camera showing only that background and the object to examine. But the problem lies when I try to Zoom in/out. What I wanna do, is I want to zoom in/out to the object, without it getting out of the background!

1- If I parent both the background and the 3d object to some empty gameobject, and try to zoom in that way (tried both orthogonal and perspective cams), both the 3d object and the background will get affected and enlarged (zoomed in/out to/from), I don’t want that, I just want the weapon/3d object to get affected, I want the background to stay still, so…

2- If I try to separate the background from the weapon, so that when I zoom in/out I only affect the weapon, what happens is that if I zoom in too much, the weapon/object will get out of the bounds/area of the background, like so:
(In this image, the background is being rendered by another camera, and the weapon by another, both cams are ortho, and I’m zooming in by changing the size of the viewport)


I hope my problem is clear. So my question is, how can I zoom in/out to the weapon, in a way that it will always be (rendered?) inside the background?

Thanks for the help.

EDIT: This is exactly what I’m trying to achieve, notice in the left image how a small portion of the right side of the shotgun isn’t showing up, same thing in the right image, the top side of the shotgun… they don’t show up, as if they’re cut.

I GOT IT!! :))

The trick was to mess with the Camera’s Normalized viewport rect, don’t let the camera render the whole screen, but only a part of it! The zooming in/out is done by ‘uniformly’ scaling the weapon (bigger/smaller)


From the docs:

Normalized View Port Rect:
Four values > that indicate where on the screen this camera view will be drawn, in Screen
Coordinates (values 0-1).
X: The beginning horizontal position that the camera view will be drawn.
Y: The beginning vertical position that the camera view will be drawn.
W: (Width) Width of the camera output on the screen.
H: (Height) Height of the camera output on the screen.

Here are my camera settings in the inspector:


I just set the beginning of the viewport to where I like within the screen, and set its width/height to fit my ‘background’ XD

Thanks for anybody who offered their help.