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 pigi5 · Jan 29, 2011 at 05:49 AM · camerazoommousewheel

ScrollWheel Input reseting?

I am trying to use the mouse scroll wheel to zoom my camera in, but when I tryed to scroll, the "Input.GetAxis" variable would change, but after I stopped scrolling it would reset back to zero, the camera zoom reseting with it. I do not know why this is happening, so any suggestions are welcome. Here is my script:

static var haveOverrided : boolean = false;

var sensitivityX : float = 15.0; var sensitivityY : float = 15.0;

var minimumX : float = -360.0; var maximumX : float = 360.0;

var minimumY : float = -60.0; var maximumY : float = 45.0;

private var rotationY : float = 0.0; private var rotationX : float = 0.0;

function Update () { if (Input.GetButton ("Fire2")) { haveOverrided = true; rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") sensitivityX; rotationY += Input.GetAxis("Mouse Y") sensitivityY; rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); } transform.localEulerAngles = Vector3(-rotationY, rotationX, 0); mouseScroll = Input.GetAxis ("Mouse ScrollWheel"); var cameraZoom = Camera.main; cameraZoom.camera.fieldOfView = mouseScroll*20+60; print (mouseScroll); }

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

1 Reply

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

Answer by DaveA · Jan 29, 2011 at 05:57 AM

If the value is zero when not moving, then use that value as a 'delta', accumulate it to a stored value (assuming it goes negative if moved in the opposite direction). Something like mouseScroll += Inout.GetAxis("MouseScrollWheel"); (but you'll need to tweak it)

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 Bunny83 · Jan 29, 2011 at 06:01 AM 0
Share

You are absolutely right. The mouse wheel is a delta input like $$anonymous$$ouse X or $$anonymous$$ouse Y. It returns how much that axis has been moved since the last frame.

avatar image pigi5 · Jan 29, 2011 at 06:06 AM 0
Share

thanks, that works great! I tweaked it to mouseScroll-=Input.GetAxis("$$anonymous$$ouse ScrollWheel") since += was inverted.

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

How to move camera on local z axis 2 Answers

Mouse wheel zoom 1 Answer

Keep Player + Party and/or Targeted Enemies in Camera Focus 1 Answer

Avoid/Minimize Sprites extrapolation in 2D while camera changes size 0 Answers

Basic Camera rotation and Zoom 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