Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • 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 this for initialization
     void Start()
     {
         this.isMouseActive = false;
         this.isCameraPositionZero = false;
         this.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 while 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()
     {
         this.currentMouseAxisX = Input.mousePosition.x;
         this.currentMouseAxisY = Input.mousePosition.y;
     }
     // get mouse axis to move
     void getMouseAxisOnClick()
     {
         this.onClickMouseAxisX = Input.mousePosition.x;
         this.onClickMouseAxisY = Input.mousePosition.y;
         //Debug.Log(" OX: " + onClickMouseAxisX + " OY: " + onClickMouseAxisY);
     }
     // get amount of move camera
     void calculateMoveMouse()
     {
         this.mouseMovementXLength = (onClickMouseAxisX - currentMouseAxisX * cameraSmoothWalue * Time.deltaTime);
         this.mouseMovementYLength = (currentMouseAxisY - onClickMouseAxisY) * cameraSmoothWalue * Time.deltaTime;
 
         this.mouseMovementYLength = Mathf.Clamp(mouseMovementYLength, minAngleY, maxAngleY);
         invertMouseMovementLenght();
         Debug.Log("LX " + mouseMovementXLength + " LY " + mouseMovementYLength);
     }
     // invert amount of camera move
     void invertMouseMovementLenght()
     {
        // this.mouseMovementXLength = -mouseMovementXLength;
         this.mouseMovementYLength = -mouseMovementYLength;
     }
     // set up camera smooth move
     public void setCameraSmoothValue(float smooth)
     {
         this.cameraSmoothWalue = smooth;
     }
     // camera rotate mechanic
     void cameraRotateAngles()
     {
         // change camera rotation on his 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 this 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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

my camera is rotating on Z axis when i just set it on X and Y 0 Answers

How to have objects rotate around a given point that are scripted to face the player 1 Answer

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

Problems with rotation after zoom (camera like Sketchfab) 0 Answers

Problems with limiting angles 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