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 sandhillceltic · Aug 22, 2013 at 01:55 AM · cameramaptopdownzoom

I am writing a camera script, but it seems not to be working. Any suggestions?

I am writing a top down camera code, so the player can navigate the map with WASD, Q&E. WASD are for movement, and Q&E are for zooming. My code seems not to be working, as the height is not changing in the inspector during play mode. I am thinking that it has something to do with the type of var I am using, but I cannot seem to fix it. All I want the code to do right now is for the height to change in the inspector. The number that appears in the inspector should be less than one, as the height of the camera (y value) is being divided by 100. Here is the script (so far)

 var sensitivity = 1;
 var lowrange = -29;
 var highrange = 30;
 var zoomrate = 1;
 var height = 0;
 
 
 
 function Update (){    
     
     
     
     if(Input.GetKey("d")){
         transform.Translate(sensitivity, 0, 0);
     }
     
     if(Input.GetKey("a")){
         transform.Translate(-sensitivity, 0, 0);
     }
     
     if(Input.GetKey("w")){
         transform.Translate(0, sensitivity, 0);
     }
     
     if(Input.GetKey("s")){
         transform.Translate(0, -sensitivity, 0);
     }
     
     if(Input.GetKey("e") && rigidbody.position.y > lowrange){
         transform.Translate(0, 0, zoomrate);
     }
     
     if(Input.GetKey("q") && rigidbody.position.y < highrange){
         transform.Translate(0, 0, -zoomrate);
     }
     
     height = rigidbody.position.y/100;
     
 }

Sorry about the poor coding style, I script weird.


A side note- This script, when finished, will allow a dynamic camera model, so that the sensitivity will be turned down when the camera is zoomed in. This stops jerky movement when zoomed in.

Ask me if you need to clarify anything. Javascript only, please.

-Thanks, Thomas

Comment
Add comment · Show 1
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 Benproductions1 · Aug 22, 2013 at 02:09 AM 0
Share

You should type your variables. It makes it easier to read, easier (faster) to compile and less prone to bugs.

You type like this:

 var floatingPoint:float = 1;

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Aug 22, 2013 at 02:08 AM

A couple of problem here. First, you say you are doing a top-down view and you are checking the 'y' position, but you are zooming on the z. Assuming that "e" key is up and "q" is down, you have your boundary check backwards. The third problem is that you should be scaling your zoom by Time.deltaTime...which also means at the top of the file that zoomrate needs to be larger.

  if(Input.GetKey(KeyCode.E) && rigidbody.position.y <=  highrange){
        transform.Translate(0, zoomrate * Time.deltaTime, 0);
     }
  
     if(Input.GetKey(KeyCode.Q) && rigidbody.position.y >= lowrange){
        transform.Translate(0, -zoomrate * Time.deltaTime, 0);
     }
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 sandhillceltic · Aug 22, 2013 at 11:52 AM 0
Share

The letters to not represent the axises. The letters are just vars that help me work. They could be k,j, and l, and it would work the same...

avatar image sandhillceltic · Aug 22, 2013 at 11:53 AM 0
Share

I will try the deltatime suggestion next

avatar image robertbu · Aug 22, 2013 at 03:16 PM 0
Share

"The letters to not represent the axises."

$$anonymous$$y point wasn't about the specific letter but about the logic. In your original code you were translating in a positive direction, but you were checking to see if it was >lowrange. This is backwards. The fix depends on your intent. if "e' is up, then the fix I gave you was correct. If "e" was down movement then the fix was to negate 'zoomrate'.

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

16 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

Related Questions

Camera only panning on 1 axis 1 Answer

Increase camera Zoom 1 Answer

Camera zooming in and out 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Problems with second Camera zoom and display 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