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 /
This question was closed Jan 19, 2015 at 11:40 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by hugemaggot · Dec 17, 2010 at 07:30 PM · camerarpg

zooming in and out with mouse wheel

im making an rpg, and im now onto the stage of doing the camera. orbiting my character ect. but i dont know how to make my camera zoom in and out using the mouse wheel, can anyone help me?

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

  • Sort: 
avatar image
4
Best Answer

Answer by _Petroz · Dec 17, 2010 at 10:01 PM

Generally 'zooming' in game is just moving the camera closer or farther away from the target. To make it zoom just adjust the camera distance with the scroll wheel.

 float cameraDistanceMax = 20f;
 float cameraDistanceMin = 5f;
 float cameraDistance = 10f;
 float scrollSpeed = 0.5f;
 
 void Update()
 {
     cameraDistance += Input.GetAxis("Mouse ScrollWheel") * scrollSpeed;
     cameraDistance = Mathf.Clamp(cameraDistance, cameraDistanceMin, cameraDistanceMax);
 
     // set camera position
 }

             
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 MerlinsMaster · Jan 19, 2015 at 11:38 AM 0
Share

Thanks, buddy. That worked like a charm.

avatar image JefferyWright · Jan 08, 2016 at 08:43 PM 0
Share

This script produced no errors, but did also not produce any results:

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$WZoom : $$anonymous$$onoBehaviour {
 
     float cameraDistance$$anonymous$$ax = 20f;
     float cameraDistance$$anonymous$$in = 5f;
     float cameraDistance = 10f;
     float scrollSpeed = 0.5f;
     
     void Update()
     {
         cameraDistance += Input.GetAxis("$$anonymous$$ouse ScrollWheel") * scrollSpeed;
         cameraDistance = $$anonymous$$athf.Clamp(cameraDistance, cameraDistance$$anonymous$$in, cameraDistance$$anonymous$$ax);
         
         // set camera position
     }
 }
 
avatar image Valoseg · Feb 04, 2016 at 09:35 PM 0
Share

Thanks man. It works just like I need it. If someone have problems with this, import the built in utility package and use script "SmoothFollow.cs", add there this lines of code:

 float height$$anonymous$$ax = 10f;
 float height$$anonymous$$in = 3f;
 float scrollSpeed = 5f;
 void Update() {
     height += Input.GetAxis("$$anonymous$$ouse ScrollWheel") * scrollSpeed;
     height = $$anonymous$$athf.Clamp(height, height$$anonymous$$in, height$$anonymous$$ax);
 }

Outstanding! Thanks again mate!

avatar image
0

Answer by sonofatrus · Jun 25, 2012 at 07:07 PM

Maybe should to manipulate with FOV when non-orthographic camera mode?

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Advanced movement and camera controls (Angrybots-ish) 0 Answers

RPG scripts 2 Answers

Smooth Follow Camera Rotate on Z-Axis? 2 Answers

Need help inserting First view controller and 3d 2 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