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 giants1 · Dec 10, 2012 at 05:54 AM · javascriptkeyboardcontrolszoom

Javascript coding on how to zoom in using keyboard

Trying to make a game similar to Slender. What is the coding to zoom using any keyboard command using javascript coding.

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

Answer by clunk47 · Dec 10, 2012 at 08:32 AM

Here's a simple javascript I put together. This uses vertical axis, which is W and S, as well as Up and Down Arrow Keys. Use these keys to zoom in and out. This uses Field of view to zoom in and out, keeping the camera in it's place. This script also has min and max zoom. Attach this script to the main camera in your scene.

 private var cam : Camera;
 var fov : float = 60f;
 var zoom_speed : float = 60.0f;
 var zoom_min : float = 30.0f;
 var zoom_max : float = 90.0f;
 
 function Start () 
 {
     cam = this.camera;
 }
 
 function Update () 
 {
     cam.fieldOfView = fov;
     
     if(fov >= zoom_max)
        fov = zoom_max;
     if(fov <= zoom_min)
        fov = zoom_min;
     if(Input.GetAxis("Vertical") > 0)
         fov+= zoom_speed * Time.smoothDeltaTime;
     else if(Input.GetAxis("Vertical") < 0)
         fov-= zoom_speed * Time.smoothDeltaTime;
         
 }
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 ChrisSch · Jul 18, 2013 at 08:58 PM 2
Share

Thank you this is exactly what I was looking for!

avatar image clunk47 · Jul 19, 2013 at 03:44 AM 1
Share

Always happy to help :)

avatar image m_atef · Oct 09, 2016 at 08:04 AM 0
Share

Hi, i tried this code on visual basic 2015 version but its not working as it gives me error as follows in the picture below.alt text So what i should change to be compitable with the current VB version? Thanks

jaav-error.png (56.2 kB)

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

12 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

Related Questions

Rotate the same way no matter what direction facing? 1 Answer

Collision not working. 1 Answer

gun scope cam not working 3 Answers

What Key do you press to "Jump" in the T_T Tutorial? 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 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