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
1
Question by Mike Ledwards · Dec 09, 2010 at 07:34 PM · mousezoomorbitwheel

Is it possible to add zoom to the mouse orbit script?

As the above states...

I want to control it with the mouse wheel/scroll. (it is added to my 3rd person camera, my game switches between 1st and 3rd)

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
2
Best Answer

Answer by Matthew Crawford · Dec 09, 2010 at 07:45 PM

Yes it's possible. Just detect the scrollwheel input and move the camera object as needed. This might point you in the right direction; http://www.unifycommunity.com/wiki/index.php?title=MouseOrbitZoom

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 Mike Ledwards · Dec 09, 2010 at 08:18 PM 0
Share

Spot on Sir ;) just what i needed

avatar image Mike Ledwards · Dec 10, 2010 at 02:53 AM 0
Share

i got it working but there is no limit on the x axes i can view 360 degree and still walk forward with it(whilst facing backward) :s

avatar image
0

Answer by deadshot · Oct 20, 2014 at 06:48 AM

for zoom

using UnityEngine; using System.Collections;

public class zoom : MonoBehaviour {

 public float zoomSensitivity= 15.0f;
 public float zoomSpeed= 5.0f;
 public float zoomMin= 5.0f;
 public float zoomMax= 80.0f;
 
 private float z;
 
 
 void Start() {
     z = camera.fieldOfView;
 }
 
 void Update() {
     z -= Input.GetAxis("Mouse ScrollWheel") * zoomSensitivity;
     z = Mathf.Clamp(z, zoomMin, zoomMax);
 }
 
 void LateUpdate() {
     camera.fieldOfView = Mathf.Lerp (camera.fieldOfView, z, Time.deltaTime * zoomSpeed);
 }

}

for mouse orbit on right click

using UnityEngine; using System.Collections;

public class rotateonmouse : MonoBehaviour { public float speed = 5.0f; public Transform target ; public float Distance = 5.0f; public float xSpeed = 250.0f; public float ySpeed = 120.0f; public float yMinLimit = -20.0f; public float yMaxLimit = 80.0f;

 private float x;
 private float y;
 
 
 
 
 
  void Awake()
 {
     Vector3 angles = transform.eulerAngles;
     x = angles.x;
     y = angles.y;
    
     if(GetComponent<Rigidbody>() != null)
     {
         rigidbody.freezeRotation = true;
     }
 }
   
 void LateUpdate()
 {
     if (Input.GetMouseButton(1)) {
     transform.LookAt(target);
     transform.RotateAround(target.position, Vector3.up, Input.GetAxis("Mouse X")*speed);
     if(target != null)
     {
         x += (float)(Input.GetAxis("Mouse X") * xSpeed * 0.02f);     
         y -= (float)(Input.GetAxis("Mouse Y") * ySpeed * 0.02f);
        
         y = ClampAngle(y, yMinLimit, yMaxLimit);
        
         Quaternion rotation = Quaternion.Euler(y, x, 0);
         transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 100.0f * Time.deltaTime);    
         Vector3 position = rotation * (new Vector3(0.0f, 0.0f, -Distance)) + target.position;
        
         transform.rotation = rotation;
         transform.position = position;
     }
     }
 }
 
 
  private float ClampAngle(float angle, float min, float max)
 {
     if(angle < -360)
     {
         angle += 360;
     }
     if(angle > 360)
     {
         angle -= 360;
     }
     return Mathf.Clamp (angle, min, max);
 }
 
 
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 

} }

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.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Mouse Wheel Zoom code not working like it should 1 Answer

Character Zoom in and out 1 Answer

what is the name of the mouse wheel in the input 2 Answers

Zooming To Mouse Position With Scroll Wheel 3 Answers

ORBIT CAMERA ZOOM LIMIT 0 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