Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by vexe · Aug 12, 2013 at 05:41 AM · camerarenderingorthographicperspectivecamera.render

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)

alt text

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. alt text

examine.png (162.7 kB)
totalbadass.png (263.1 kB)
Comment
Add comment · Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Seth-Bergman · Aug 12, 2013 at 05:45 AM 0
Share

by "background", you mean the shaded box in the image, correct?

avatar image vexe · Aug 12, 2013 at 05:55 AM 0
Share

Yes, correct.

avatar image Joyrider · Aug 12, 2013 at 06:53 AM 0
Share

Are you using Unity Pro? $$anonymous$$y guess would be with a screenspace shader and a mask. Or just a screenspace shader that would render the weapon onto the backgrond object.

avatar image vexe · Aug 12, 2013 at 07:09 AM 0
Share

Unfortunately 'currently' no, I'm not using Unity Pro. But does it have to be pro for me to do this? - Any other way around?

avatar image robertbu · Aug 12, 2013 at 07:17 AM 0
Share

After reading your question, I'm not sure what you consider an acceptable solution. You can calculate the relative size of objects as viewed by the camera by converting to Viewport coordinates. Viewport coordinates start in the lower left of the screen at (0,0) and go to (1,1) in the upper right. Convert the lower left corner and upper right of your 'background' to viewport coordinates. Do the same for the gun. Then you can compare their relative screen sizes.

The conversion is done using Camera.WorldtoViewportPoint().

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by vexe · Aug 12, 2013 at 09:06 AM

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)

alt text

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:

alt text

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.


totalbadass.png (29.1 kB)
totalbadass.png (77.8 kB)
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Aug 12, 2013 at 09:13 AM 0
Share

$$anonymous$$eep in $$anonymous$$d that the Camera component also has the pixelRect property which allows you to set the cameras rest in screen coordinates ins$$anonymous$$d of normalized coordinates. Note: screen coordinates have 0,0 at the bottom left corner.

avatar image vexe · Aug 12, 2013 at 09:28 AM 0
Share

Thanks, this is very useful, I will keep that in $$anonymous$$d. I've always wondered what those 'things' do in the camera :D

avatar image vexe · Aug 12, 2013 at 09:33 AM 0
Share

But strange why the property is only accessible via code, couldn't find it in the inspector... :/

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Orthographic position to Perspective position 0 Answers

Is it possible to view two camera at the same time? 2 Answers

flickering lines when zooming fov (both GUI and ortho cameras). 2 Answers

orthographic camera view looks different from perspective view 2 Answers

Adjust Camera PixelRect Based on Screen Resolution In Unity 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges