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 adventurepark · Sep 13, 2012 at 12:42 PM · cameramovingxyz

Movin' camera in XYZ

Hi Everyone, i completely new to unity scripting. I´m working on a camera flight through a landscape. Navigating in x and z space by pressing buttons works fine. i used this script:

  function Update () { 
       var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed; 
       var z = Input.GetAxis("Vertical") * Time.deltaTime * speed; 
       transform.Translate(x, 0, z); 
  } 

but now i try to move in y direction as well as in z direction. WSAD control x&y. how can i assign other keys to move in y space? thank you for your help dirk

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 AlucardJay · Sep 13, 2012 at 12:56 PM 0
Share

I just formatted your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window =]

6 Replies

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

Answer by AlucardJay · Sep 13, 2012 at 12:58 PM

You can use the Input Manager :

http://docs.unity3d.com/Documentation/Components/class-InputManager.html

http://docs.unity3d.com/Documentation/Manual/Input.html

or use GetKey :

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetKey.html

 function Update () { 
     var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed; 
     var z = Input.GetAxis("Vertical") * Time.deltaTime * speed; 
     var y : float;
     if (Input.GetKey(KeyCode.Q)) {
         y = -1.0 * Time.deltaTime * speed; 
     }
     else if (Input.GetKey(KeyCode.E)) {
         y = 1.0 * Time.deltaTime * speed; 
     }
     transform.Translate(x, y, z); 
 } 
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
avatar image
0

Answer by adventurepark · Sep 13, 2012 at 01:06 PM

thanks jay kay!

Comment
Add comment · Show 1 · 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 AlucardJay · Sep 13, 2012 at 01:32 PM 0
Share

Hi There. No worries, happy if some of this info helped. There is Input $$anonymous$$anager (as alot of people have linked to!) or Get$$anonymous$$ey / Get$$anonymous$$eyDown/Get$$anonymous$$eyUp. I thought I would show an example of Get$$anonymous$$ey just to show something different.

Oh, by the way :

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

You can convert this answer to a comment (or just edit your original question), you'll also get a better chance of getting an actual answer if the main list shows none or one answer in blue =]

avatar image
0

Answer by save · Sep 13, 2012 at 01:00 PM

Create a new axis in the Input Manager called "Altitude" with a negative and positive button.

 function Update () { 
     var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
     var y = Input.GetAxis("Altitude") * Time.deltaTime * speed;
     var z = Input.GetAxis("Vertical") * Time.deltaTime * speed; 
     transform.Translate(x, y, z); 
 } 


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
avatar image
0

Answer by electricsauce · Sep 13, 2012 at 01:00 PM

Input.GetButtonDown("Fire1");

assign Fire1 to whatever you like

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
avatar image
0

Answer by hoffmanuel · Sep 13, 2012 at 01:06 PM

Hi!

In your Scenario you are using axis, not keys at the moment. You can add axis or keys via the Input Manager (Edit->Project Settings->Input) You see, Horizontal and Vertical are there defined Already. You Could add an own one by increasing the Size by one and changing the name of the bottommost element to your chosen one.

[Input Manager Reference][1]

Alternately you could use Input.GetKey(KeyCode.[YourKey]) in your code to get your wanted behaviour.

br [1]: http://docs.unity3d.com/Documentation/Components/class-InputManager.html

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
  • 1
  • 2
  • ›

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

13 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

Related Questions

Problem when applying forces to a ball 1 Answer

Help|MouseLook Y-Axis moving in the wrong direction 1 Answer

Fade between two moving cameras 1 Answer

How do I make my flashlight follow the camera when moving? 2 Answers

Getting camera to not see under the ground 3 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