• 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 /
  • Help Room /
avatar image
0
Question by GimpG1K · Aug 17, 2016 at 11:52 AM · camerarotationscripting problemrotation axislength

Camera self rotation script problem

Hello my problem is: I want to rotate my camera in length (from -> to) actually cursor location(from) -> length betwen cursor start position and position changing on click (to). I had problem with configure it because my camera is jumping and not moving smoothly. Second problem is that I want to rotate camera in length just from click not from the last position of cursor

The code is:

 // set up before scene start
     void Awake()
     {
         cameraDefault = Camera.main;
         standardCameraAnglesOfView();
         setCameraSmoothValue(0.1f);
     }
     // use t$$anonymous$$s for initialization
     void Start()
     {
         t$$anonymous$$s.isMouseActive = false;
         t$$anonymous$$s.isCameraPositionZero = false;
         t$$anonymous$$s.isCameraRotationZero = false;
         cameraPositionChecker();
         cameraRotationChecker();
     }
     // per frame
     void LateUpdate ()
     {
         getMouseAxisPerFrame();
         checkMouseStatus();
         onMouseHold();
     }
 // check if left mouse button is holded
     void checkMouseStatus()
     {
             if (Input.GetMouseButton(0))
             {
                 isMouseActive = true;
             }
             else
             {
                 isMouseActive = false;
             }      
     }
     // action used to be done w$$anonymous$$le is holding left mouse button
     void onMouseHold()
     {
         if (isMouseActive)
         {
             if (currentMouseAxisX != onClickMouseAxisX && currentMouseAxisY != onClickMouseAxisY)
             {
                 getMouseAxisOnClick();
                 calculateMoveMouse();
                 cameraRotateAngles();
                 Debug.Log("pressed");
             }
         }
         else if (!isMouseActive)
         {
             //Debug.Log(" CX " + currentMouseAxisX + " CY " + currentMouseAxisY);
             Debug.Log("release");
         }
 
     }
     // get mouse axis every frame
     void getMouseAxisPerFrame()
     {
         t$$anonymous$$s.currentMouseAxisX = Input.mousePosition.x;
         t$$anonymous$$s.currentMouseAxisY = Input.mousePosition.y;
     }
     // get mouse axis to move
     void getMouseAxisOnClick()
     {
         t$$anonymous$$s.onClickMouseAxisX = Input.mousePosition.x;
         t$$anonymous$$s.onClickMouseAxisY = Input.mousePosition.y;
         //Debug.Log(" OX: " + onClickMouseAxisX + " OY: " + onClickMouseAxisY);
     }
     // get amount of move camera
     void calculateMoveMouse()
     {
         t$$anonymous$$s.mouseMovementXLength = (onClickMouseAxisX - currentMouseAxisX * cameraSmoothWalue * Time.deltaTime);
         t$$anonymous$$s.mouseMovementYLength = (currentMouseAxisY - onClickMouseAxisY) * cameraSmoothWalue * Time.deltaTime;
 
         t$$anonymous$$s.mouseMovementYLength = Mathf.Clamp(mouseMovementYLength, minAngleY, maxAngleY);
         invertMouseMovementLenght();
         Debug.Log("LX " + mouseMovementXLength + " LY " + mouseMovementYLength);
     }
     // invert amount of camera move
     void invertMouseMovementLenght()
     {
        // t$$anonymous$$s.mouseMovementXLength = -mouseMovementXLength;
         t$$anonymous$$s.mouseMovementYLength = -mouseMovementYLength;
     }
     // set up camera smooth move
     public void setCameraSmoothValue(float smooth)
     {
         t$$anonymous$$s.cameraSmoothWalue = smooth;
     }
     // camera rotate mechanic
     void cameraRotateAngles()
     {
         // change camera rotation on $$anonymous$$s own axis
         //cameraDefault.transform.rotation = Quaternion.Euler(mouseMovementYLength, mouseMovementXLength, 0 );
         cameraDefault.transform.Rotate(mouseMovementYLength, mouseMovementXLength, 0);
     }
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
Best Answer

Answer by GimpG1K · Aug 18, 2016 at 12:45 AM

Fixed by using another method of rotation you can check t$$anonymous$$s out here: http://wiki.unity3d.com/index.php/SmoothMouseLook

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why won't my model rotate up on X axis? 1 Answer

Quaternion Roation Mouse Script 0 Answers

I have some Rotation problems 1 Answer

Problems with limiting angles 1 Answer

Make camera rotate around an object while keeping entire area visible 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