Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ina · Apr 29, 2011 at 04:45 AM · cameracamera-movementzoom

Smoothly zoom object at point or camera boundaries

How do you smoothly zoom an object at a certain point at runtime? Would you scale/move the object, or change the camera boundaries? In the latter case, how do you make sure the camera contains the point?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Uzquiano · Apr 29, 2011 at 11:12 AM

Hi,

Maybe you didn't find this post, it could be interesting for you.

But another solution could be to change 'smoothly' the distance in the x-z plane to the target, I mean, if the distance is 10, i would go through 9.9, 9.8...

Your knowlegde of Unity is better than mine, though your question is very interesting, and for me challenging, so I though about the possiblity of take as inspiration the 'ThirdPersonCamera' script that it is in the 3rd person controller provided on the character controller package, especially in the Awake() function. So, if you want to the object is contained, maybe it should be the target of the camera...

function Awake () { if(!cameraTransform && Camera.main) cameraTransform = Camera.main.transform; if(!cameraTransform) { Debug.Log("Please assign a camera to the ThirdPersonCamera script."); enabled = false; }

 _target = transform;
 if (_target)
 {
     controller = _target.GetComponent(ThirdPersonController);
 }

 if (controller)
 {
     var characterController : CharacterController = _target.collider;
     centerOffset = characterController.bounds.center - _target.position;
     headOffset = centerOffset;
     headOffset.y = characterController.bounds.max.y - _target.position.y;
 }
 else
     Debug.Log("Please assign a target to the camera that has a ThirdPersonController script attached.");


 Cut(_target, centerOffset);

}

I hope this could help you.

Cheers

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

Answer by CHPedersen · Apr 29, 2011 at 11:22 AM

In general, don't move the camera closer to geometry, or geometry closer to the camera. While this does make the object appear bigger, it can also have unintended consequences for other game mechanics, such as collisions, etc. Imagine an FPS where the player has a sniper rifle, and you'd like to zoom whenever the player looks through the scope. If you do that by moving the camera forward, then the player's actual position changes and so is no longer reliable for checking whether you're in sight of enemies, affected by area-effects, etc.

Instead, the physically correct way to go about zooming is to change the camera's field of view. You zoom in by decreasing the field of view and out by increasing it. This makes intuitive sense as well, since if your field of view is smaller, then objects that are inside of it are going to take up more of the resulting screen space, i.e. appear larger.

To change it smoothly, use Mathf.lerp to set it progressively over some amount of frames. If you don't know how, I can cook you up a small example later. :P

Comment
Add comment · Show 4 · 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 Uzquiano · Apr 29, 2011 at 11:32 AM 0
Share

Hi, you are totally right about the 'field of view' but how can you assure that your target is inside the view? This is kind of tricky question ;)

avatar image CHPedersen · Apr 29, 2011 at 12:17 PM 0
Share

If you want to make sure the object to be zoomed at is going to be inside the view frustum after the field of view is changed, you can center it in the camera, i.e. set camera.transform.forward to point directly at the object. An object at the center of the camera's field of view stays in the center after changes to the field of view.

If you're asking for a way to figure out whether an object is going to be visible after the zoom has taken place, this is the same as the check that goes on in view frustum culling. It involves checking the object against the 4 planes of the frustum.

avatar image ina · Apr 30, 2011 at 01:30 AM 0
Share

wouldn't you have to move the camera if the point is behind a particular object occluding the cam?

avatar image CHPedersen · May 02, 2011 at 06:26 AM 0
Share

Well, if you want to be able to see behind occluding objects, yes. But then it's not strictly "zoom" any more. Zoo$$anonymous$$g at an occluded point shouldn't cause it to become visible. Think about it - Can you see through walls with a sniper scope?

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

No one has followed this question yet.

Related Questions

Pinch zoom 0 Answers

Problems making a smash bros like camera 2 Answers

Modified Mobile TapControl.js logic flow works, but No Apparent Cam Zoom/Rotate Response 1 Answer

Sketchup-style camera movement/rotation?. 0 Answers

I can not find Cinemachine in package manager. There is no option of 'All Assets in package manager.' 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