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 iphelan · Dec 17, 2013 at 02:16 PM · camerasnapmouseorbit

Mouse Orbit after changing Position sets camera back to last position

Hi,

I am really stuck on this code and I know I am doing something stupid. I have a camera that is is getting the mouse input and a target to use for a mouse orbit. There is another script on objects that when clicked sets a flag for moving the camera with a lerp to the object.

This all works fine except when I try and do a manual mouse orbit again because it snaps the camera back to the last position I was at during the last mouse orbit.

I have tried to offset it and a couple of other stabs at the dark but having no luck so have given up. It would be great if someone could give a hand and I do hope that all makes sense.

Edit: Also this is it running which will do a better job explaining it. http://3dsteve.co.uk/camerawebbuild/camerawebbuilt.html

 function LateUpdate () 
 {
     if(Input.GetMouseButton(0) && !selectanatomy.moving && GUIUtility.hotControl == 0) 
     {
         x +=  Input.GetAxis("Mouse X") * xSpeed * 0.02;
         y -=  Input.GetAxis("Mouse Y") * ySpeed * 0.02;
  
          y = ClampAngle(y, yMinLimit, yMaxLimit);
  
         var rotation = Quaternion.Euler(y, x, 0.0);
         var position = rotation * Vector3(0.0, 0.0, -distance) + target.transform.position;
          
         transform.rotation = rotation;
         transform.position = position;
     }
     
     if(selectanatomy.moving)    //object clicked sets this to true
     {
         transform.position = Vector3.Lerp(transform.position, targetposition.transform.position, Time.deltaTime * 5);
         
         renablecamera();
     }
 }
 
 function renablecamera()
 {
     yield WaitForSeconds (1.0);
 
     //I THINK THIS IS WHERE I NEED TO RESET THE ROTATION OF THE CAMERA TO A NEW X AND Y POSITION BASED ON WHERE THE TARGET POSITION IS 
 
     selectanatomy.moving = false;
 }
  
 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 Melih Şimşek · Dec 17, 2013 at 03:52 PM

In Start() function, you have to get Camera Original Rotation:

 origintalRotation = transform.localRotation;

Then,

In Update() function, set the rotation to the Camera

 Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
 
 Quaternion  yQuaternion = Quaternion.AngleAxis(rotationy, Vector3.left);
 
 transform.localRotation = originalRotation * xQuaternion * yQuaternion
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 iphelan · Dec 18, 2013 at 09:48 AM 0
Share

Thanks very much for the above code, it seems like it should work but it sadly did not do the job.

It may be worth noting that the script is attached to an empty gameobject and the camera has a smoothfollow on it with that object as the target.

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

18 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

Related Questions

Camera (mouse orbit), linecast and shakiness 1 Answer

Rotate around object at a given angle 2 Answers

How to make camera position relative to a specific target. 1 Answer

camera slides and bounces while moving C# 1 Answer

Camera animation issue 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