• 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 Bikebreck · Sep 21, 2010 at 02:48 AM · zoom

Does some one have a zooming script?

Can someone tell me how to do a zoom in zoom out script?

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

4 Replies

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

Answer by efge · Feb 26, 2011 at 03:32 PM

A modified MouseOrbit (from the Standard Assets) script. Move the camera forward or backward along its forward axis by the mouse scrollwheel:

var target : Transform; var distance = 10.0;

var xSpeed = 250.0; var ySpeed = 120.0;

var yMinLimit = -20; var yMaxLimit = 80;

private var x = 0.0; private var y = 0.0;

@script AddComponentMenu("Camera-Control/Mouse Orbit")

function Start () { var angles = transform.eulerAngles; x = angles.y; y = angles.x;

 // Make the rigid body not change rotation
 if (rigidbody)
     rigidbody.freezeRotation = true;

}

function LateUpdate () { if (target) { x += Input.GetAxis("Mouse X") xSpeed 0.02; y -= Input.GetAxis("Mouse Y") ySpeed 0.02;

     y = ClampAngle(y, yMinLimit, yMaxLimit);

     distance += Input.GetAxis ("Mouse ScrollWheel");
     if (distance < 3)
         distance = 3; 

     var rotation = Quaternion.Euler(y, x, 0);
     var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;

     transform.rotation = rotation;
     transform.position = position;
 }

}

static function ClampAngle (angle : float, min : float, max : float) { if (angle < -360) angle += 360; if (angle > 360) angle -= 360; return Mathf.Clamp (angle, min, max); }

Comment
Add comment · Show 2 · 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 _MGB_ · Feb 26, 2011 at 05:26 PM 0
Share

It's not advisable to move the camera to zoom - you may intersect the objects being viewed.

avatar image efge · Feb 26, 2011 at 10:56 PM 0
Share

Right, but it is perfect for a 3d turntable application because you do not change perspective and you can set a $$anonymous$$imum distance.

avatar image
2

Answer by Jesse Anders · Sep 21, 2010 at 05:10 AM

Two common ways of implementing zoom are to modify the field of view for perspective projection (decrease to zoom in, increase to zoom out) or orthographic height for orthographic projection (similar), or to move the camera forward or backward along its forward axis.

Which method to use depends on what type of camera you're implementing and what sort of behavior you want. If you need more help than that, perhaps you could clarify your question (specifically what type of behavior you're looking for, and what aspect of the implementation you need help with).

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 name111 · Oct 06, 2010 at 08:40 PM

u could simply go to Dastardlybanana.com it was a great find for me. download the weapons pack and in it is a aimmode thing. allowing u not only to aim in a scope. etc but also aim down the sights.

so lets say u wanna look through binoculars . U CAN. just find or make a picture with a scope texture but for binocs in other words a scope with 2 circles when u zoom in

in addition to d that u'll need of course the binoculars

hope i code help

PathKiller29

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 Hei · Feb 26, 2011 at 02:56 PM

You can use this script

//Camera zoom script

// Camera var cam : Camera;

function Update() { if(Input.GetButtonDown("Fire2")) { cam.fieldOfView = 30; } if(Input.GetButtonUp("Fire2")) { cam.fieldOfView = 60; } }

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

zooming in and out 1 Answer

my camera zooms when I hit the arrow keys - not sure how to disable 1 Answer

2D camera zoom in comparison to the height of target 2 Answers

How do I scale just the time portion of the animation view timeline? 2 Answers

Ortho camera zoom to mouse point 4 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