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
0
Question by Eowyn27 · Dec 20, 2013 at 02:08 PM · camerajavascriptzoomselection

I want to select an object and have the camera zoom in but inactive the other objects. I am having problems

This is a follow up to this question: http://answers.unity3d.com/questions/598995/how-can-i-select-single-out-and-zoom-into-my-objec.html#comment-600180

For more complex objects and scenes, I tried to assign the script to my main camera. However, my objects disappeared including what was supposed to be zoomed in and rendered. If I play the scene for game view and then pause the view, it appears that the piece that was supposed to be isolated and zoomed into is shown (the only object shown out of the whole structure) but for some reason, it does not render in game view. It only shows up when I pause the view.

Why is that?

Comment
Add comment
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

1 Reply

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

Answer by robertbu · Dec 20, 2013 at 02:49 PM

As a guess, the issue is the size of the object. The code zooms by moving the camera forward. If the object is large, then moving the camera in puts the surface of the object beyond the near clip plane of the camera. Result: the object disappears. Edit line 23:

 camPos.z += 5.0; // Zoom

Select a smaller number than 5.0. Note this may not be the complete or right fix for your game. There are a couple of other things you can do. The first is in your initial setup, move the camera back away from object and then narrow the field of view of the camera. This will give you more working room for your zoom while maintaining the same object size. You can then edit the '5.0' in the line above as appropriate.

The second thing that can be done is to recode the zoom so that it change the field of view rather than moves the camera. Given the camera was already going to move sideways to center the object, moving it forward was the simplest solution.

Comment
Add comment · Show 7 · 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 Eowyn27 · Dec 23, 2013 at 03:46 AM 0
Share

Hi, I changed my zoom setting to 0.25 and I was able to see my object. However, my object was not zoomed in and it appeared small. It was isolated from the other objects but not zoomed in. So, I was wondering how do I have it zoomed in but appear in the scene? I was looking at changing the field of view but I wasn't sure how I would do that. Would you mean if that I need to adjust the near and far clipping plan?

avatar image robertbu · Dec 23, 2013 at 06:54 AM 0
Share

The default clipping planes are fine, so unless you've edited them, changing the clip planes is not the solution. What I recommend is as follows:

  • In edit mode, click on the camera in your hierarchy.

  • In the Inspector decrease the field of view. For this test, cut it in half. For example if it is set at 60, change it to 30.

  • Now double the distance of your camera to your objects. For example if your camera is at -10 on the 'z' axis as is the default, move it to -20 on the 'z' axis.

Now run your app. You may have to adjust how far you move the camera forward to get the zoom you want. For example:

 camPos.z += 8.0; 

Note zoo$$anonymous$$g by adjusting the camera's field of view is another option. Code to zoom the FOV has been posted to UA many times.

avatar image Eowyn27 · Dec 23, 2013 at 03:42 PM 0
Share

The camera is orthographic. I would have to change the size of my orthographic camera for the field of view? (as there's no field of view for orthographic cameras). Also, I disabled camPos.x and CamPos.y because I don't need the object itself to move (It moves when I select it) and it seems fine. I just need to zoom it in the z direction but I'm not sure how to zoom in z direction without having the camera make the object disappear.

avatar image robertbu · Dec 23, 2013 at 05:27 PM 0
Share

If the camera is orthographic, then you will have to change the orthographic size of the camera to zoom. Here is a bit of demonstration code on one way to zoom the size. Note the small the size, the larger the object (the more zoomed in):

 #pragma strict
 
 var speed = 2.5;
 
 function Update() {
      if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Z)) {
          OrthoZoom(1.5);
      }
 }
 
 function OrthoZoom(size : float) {
     var cam = Camera.main;
     
     while (cam.orthographicSize != size) {
         cam.orthographicSize = $$anonymous$$athf.$$anonymous$$oveTowards(cam.orthographicSize, size, speed * Time.deltaTime);
         yield;
     }
 }
avatar image Eowyn27 · Dec 23, 2013 at 06:45 PM 0
Share

Hmm, nothing happens to the zoom. Here's how I manipulated your code:

 var camPos : Vector3; 
 var camTr  : Transform;
 var speed = 2.5;
 
 function Start() {
 camTr  = Camera.main.transform;
 camPos = camTr.position;
 }
 
 function Update() {
 
 if (Input.Get$$anonymous$$ouseButtonDown(0)) {
    var hit : RaycastHit;
    var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, hit) && hit.collider.tag == "block") {
      var blocks = GameObject.FindGameObjectsWithTag("block");
      for (var go : GameObject in blocks) {
       if (go == hit.collider.gameObject) {
          //camPos.x = go.transform.position.x;
         // camPos.y = go.transform.position.y;
       //   camPos.z += .05; // Zoom
          
          if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Z)) {
          OrthoZoom(3);
          }
          
  
           }
       
       else {
           go.SetActive(false);
         
       }
      }
    }
 }
 
 camTr.position = Vector3.Lerp(camTr.position, camPos, Time.deltaTime * speed);
 
   
 
 }
 
 function OrthoZoom(size : float) {
 var cam = Camera.main;
 
 while (cam.orthographicSize != size) {cam.orthographicSize = $$anonymous$$athf.$$anonymous$$oveTowards(cam.orthographicSize, size, speed * Time.deltaTime);
 yield;

} }

Show more comments

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

camera zoom 1 Answer

Clamping a 2D camera while zooming. 0 Answers

Limiting Camera Movement 1 Answer

Camera scripting references 0 Answers

Camera too zoomed in in built game 1 Answer


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