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 yoda12 · Feb 19, 2015 at 11:36 PM · cameramovementsmooth

[SOLVED]Why is this scripts output so choppy/glitchy?

[UPDATE]So the following script basically is not smooth, and I know there are ways to fix this but I am not entirely sure how...

(end of update)

I am trying to make a camera script that will move the camera horizontally with the mouse while the middle button is being held down, meaning forward left, right, back, and diagonal, but not up and down; What happens is that it works, but is choppy. How can I fix this? Btw, it has to be attached to the camera to work: movecamera.js:

  #pragma strict
  
  //NOTE: THIS SCRIPT HAS TO BE ATTACHED TO THE CAMERA TO WORK!
  
  function Update () {
  
  
  var flySpeed = 1;
  if(Input.GetMouseButton(2)){//For middle click
    
    if(Input.GetAxis("Mouse X")<0){//Left
        transform.Translate(Vector3.left * flySpeed);
    
        }
    if(Input.GetAxis("Mouse X")>0){//Right
    transform.Translate(Vector3.right * flySpeed);
  
    }
    if(Input.GetAxis("Mouse Y")>0){//Forward
    transform.Translate(Vector3.forward * flySpeed);
    
    }
    if(Input.GetAxis("Mouse Y")<0){//backward
    transform.Translate(Vector3.back * flySpeed);
    
    }
    
    }
    
   }
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

2 Replies

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

Answer by yoda12 · Feb 23, 2015 at 12:49 AM

I solved the problem by basically doing what MonkeyHood had said, only by tracking the cameras position and using division. Thanks!

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
1
Wiki

Answer by MonkeyHood · Feb 19, 2015 at 11:47 PM

It's choppy because you always move the same distance every frame.

 Vector3.left * flySpeed

I don't really know JS, so you will have to write the code yourself, but here's what you should do.

  1. save the mouse position in a var (lastMousePosition) as soon as the button is pushed

  2. Next frame, if the button is still held down, take the current position and subtract lastMousePosition from it, store it in mouseDistance

  3. If the mouse button is let go, set LastMousePosition to Vector3.zero

Your new Translate() functions should look like this:

 transform.Translate(Vector3.left * flySpeed * MouseDistance);
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 yoda12 · Feb 23, 2015 at 12:12 AM 0
Share

Well, I think I get your point there, but I don't completely understand what you mean, but for instance when you move the camera this way, you keep the middle mouse button held down.

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

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

Related Questions

How to smooth my camera (Vector3.Lerp) 0 Answers

Problems with Lerp. 1 Answer

Smooth Camera Follow Script, Weird Movement... Please help! 1 Answer

Smooth Camera Movement 1 Answer

Smooth Camera/Object Movement 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