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 omatase · Jan 27, 2015 at 02:05 AM · camerarotationquaterniongetaxis

Rotate camera on mouse drag, minor glitch

I have a script I modified from the standard scripts mouseOrbit library. I have a scene and I just want people to be able to click and hold the left mouse button and while holding, drag to rotate the camera. It pretty much works exactly as it should except one minor issue. The very first time the scene loads, whenever I left click in the scene the camera rotation jumps noticeably to the right. Thereafter it works as expected, and only repositions if I click, hold and drag. But for some reason the first time I single click it jumps. Would appreciate someone's suggestion on what might be happening.

Here's the modified script. It should be pretty straight forward. It stores the x and y angle of rotation on startup, then on late update whenever the mouse is held down it gets the change in x and y axis and rotates based off that changed value.

Appreciate the help in advance!

 var xSpeed = 250.0;
 var ySpeed = 120.0;
 
 var yMinLimit = -20;
 var yMaxLimit = 80;
 
 var xMinLimit = -20;
 var xMaxLimit = 80;
 
 private var x = 0.0;
 private var y = 0.0;
 
 @script AddComponentMenu("Camera-Control/Mouse Orbit")
 
 function Start () {    
 
     var angles = gameObject.transform.eulerAngles;
     y = transform.rotation.y;
     x = transform.rotation.x;
 
     // Make the rigid body not change rotation
     if (GetComponent.<Rigidbody>())
         GetComponent.<Rigidbody>().freezeRotation = true;
 }
 
 function LateUpdate () {
 
     if (Input.GetMouseButton(0)) {
 
         x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
         
         y = ClampAngle(y, yMinLimit, yMaxLimit);
         x = ClampAngle(x, xMinLimit, xMaxLimit);
 
         var rotation = Quaternion.Euler(y, x, 0);
         
         transform.rotation = rotation;
     }
 }
 
 static function ClampAngle (angle : float, min : float, max : float) {
     if (angle < -360)
         angle += 360;
     if (angle > 360)
         angle -= 360;
     return Mathf.Clamp (angle, min, max);
 }
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 Bentoon · Jan 27, 2015 at 04:09 AM

Hey,

Maybe its another script or parameter on camera. I tried in a blank scene and there is no jumping

~be

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 omatase · Jan 29, 2015 at 01:32 AM 0
Share

O$$anonymous$$, thanks @Benton. I just started thinking I might have something somewhere else causing this jump. Appreciate your time. I'll come back and add more details if I have more to add.

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

20 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

Related Questions

How to force camera rotation? 1 Answer

Edited mouselook script rotation clamp not working 0 Answers

True Portal Effect 1 Answer

Transition current camera rotation to 0,0,0 1 Answer

How to synchronize both movement and rotation? 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