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 Wrymnn · Nov 08, 2014 at 09:55 PM · zoom

Smooth 2D camera zoom

Have 2D Top Down game.

I need some Smooth Ortographic Camera zoom in it. So far this is not working, it`s pretty fast and not smooth.

 camera.orthographicSize = Mathf.Lerp(camera.orthographicSize, camera.orthographicSize + Input.GetAxis("Mouse ScrollWheel") * 100, Time.deltaTime * zoomSpeed);


Any Ideas please?

Comment
Add comment · Show 5
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 MrSoad · Nov 08, 2014 at 09:59 PM 0
Share

Where are you running this code, if it is not in LateUpdate() then try it here and see if the result is the same.

avatar image Wrymnn · Nov 08, 2014 at 10:39 PM 0
Share

No tried late update, still no sign of Smoothness.

avatar image MrSoad · Nov 08, 2014 at 10:58 PM 0
Share

Have you tried moving the camera ins$$anonymous$$d of changing its size?

avatar image Wrymnn · Nov 09, 2014 at 07:32 AM 0
Share

No this is 2d game and size it's ortographic I can move it kilometer from objects t hg eye will always be the same size

avatar image MrSoad · Nov 09, 2014 at 11:25 AM 0
Share

Yes sorry, not thinking right at all there :S

2 Replies

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

Answer by SarperS · Nov 09, 2014 at 11:16 AM

It is fast because the usage of the Lerp method is wrong. For the third parameter your argument is

 Time.deltaTime * zoomSpeed

The way the lerp works is, if this parameter is 0 it returns your first argument camera.orthographicSize. If it's 1 it return your second argument. The values in-between interpolate between your both arguments. Hope it makes sense. So what you want to do is, map the zoom value between 0 and 1, modify that value with the scroll wheel and then use that as an argument for the lerp. Let me know if it doesn't make any sense and I can provide a code example in my free time.

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
9

Answer by Tap2Continue · Dec 20, 2014 at 11:22 PM

Here's an awesome script. It works perfectly

 using UnityEngine;
 using System.Collections;
 
 public class Zoom : MonoBehaviour {
     
     public float zoomSpeed = 1;
     public float targetOrtho;
     public float smoothSpeed = 2.0f;
     public float minOrtho = 1.0f;
     public float maxOrtho = 20.0f;
     
     void Start() {
         targetOrtho = Camera.main.orthographicSize;
     }
     
     void Update () {
         
         float scroll = Input.GetAxis ("Mouse ScrollWheel");
         if (scroll != 0.0f) {
             targetOrtho -= scroll * zoomSpeed;
             targetOrtho = Mathf.Clamp (targetOrtho, minOrtho, maxOrtho);
         }
         
         Camera.main.orthographicSize = Mathf.MoveTowards (Camera.main.orthographicSize, targetOrtho, smoothSpeed * Time.deltaTime);
     }
 }

Comment
Add comment · Show 1 · 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 unity_A45BCE65BAFAC946F74C · May 05 at 08:32 PM 0
Share

Idk how the duck u fixed my code somehow but thanks man :)

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

30 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 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 scripting references 0 Answers

Problems with second Camera zoom and display 1 Answer

Sniper Scope with zoom 1 Answer

How to centre a 3D pinch zoom 1 Answer

2.5d Side Scroller Dynamic Camera Zoom 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