Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Nightmare_Games · Apr 27, 2017 at 09:21 AM · inputcamera movementscrollingkeyboard inputpanning

Input + Camera Movement

I wrote a script to move the camera via the keyboard. I pieced this together using various piece of the Roll A Ball tutorial. However, the camera continues moving for about a half second after I release the key. Obviously that's not optimal performance. Here's the script:

 public class camera_controller : MonoBehaviour
   {
   void Update ()
     {
     float horizontal = Input.GetAxis ("Pan Horizontal");
     float vertical   = Input.GetAxis ("Pan Vertical");
     float zoom       = Input.GetAxis ("Zoom");
     Vector3 position = transform.position;

     if (horizontal < 0) position.x += .1f;
     if (horizontal > 0) position.x -= .1f;
     if (vertical < 0) position.z += .1f;
     if (vertical > 0) position.z -= .1f;
     if (zoom < 0) position.y += .5f;
     if (zoom > 0) position.y -= .5f;

     transform.position = position;
     }
   }

There seems to be a LOT of variations on how to do this, but most of the examples I've seen are using Time.deltaTime in the math somewhere. I didn't originally have that, but adding it in hasn't really affected anything, aside from slowing the scrolling way down.

     if (horizontal < 0) position.x += 10f * Time.deltaTime;

What about the way I wrote my script is causing the input delay? I'd rather understand the code rather than just copy/paste something that "works" without having learned anything.

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
0

Answer by ShadyProductions · Apr 27, 2017 at 10:46 AM

You could do something much easier:

    void Update ()
    {
      float horizontal = Input.GetAxis ("Pan Horizontal");
      float vertical = Input.GetAxis ("Pan Vertical");
      float zoom = Input.GetAxis ("Zoom");
      float speed = 5f;

      transform.Translate(horizontal * speed * Time.deltaTime, zoom * speed * Time.deltaTime, vertical * speed * Time.deltaTime);
    }

Also, shouldn't zoom be the Z axis instead of the Y and vertical be the Y axis and not the Z?

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 Steel598 · Apr 29, 2017 at 02:00 AM 0
Share

@ShadyProductions Unity does not like the transform.translate line, is there another way to do this?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Enable/Disable button input 1 Answer

simulate pc keyboard input in android touch screen keyboard 0 Answers

query keyboard mapping in new input system 0 Answers

Keyboard Input + Camera Movement 1 Answer

Scroll input carrying over to next scene 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