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 Shodycool · Aug 20, 2013 at 06:02 AM · cameracamera-lookorientation

How Can I make the camera stop reorienting itself?

I am currently making a game in which the player doesn't need down to be down,and up to be up. Every time I look too far down (As if to be upside down now) it reorients itself so up is up. Same with looking too far up. As far as i can tell, i have no code interfering with its orientation. I'm wondering if it is something that the camera does on its own, and if i can override it somehow.

*edit i got this straight from the widget model game w/ minor changes. ie it doesnt need height becuase the camera can rotate with the player

 var target : Transform;
 var distance = 10.0;

 //var heightDamping = 2.0;
 var rotationDamping = 3.0;
 var distanceDampingX = 0.5;
 var distanceDampingZ = 0.2;

 var camSpeed = 2.0;
 var smoothed = true;

 function LateUpdate () {
 // Check to make sure a target has been assigned in Inspector
 if (!target)
     return;
 
 // Calculate the current rotation angles, positions, and where we want the camera to end up
 wantedRotationAngle = target.eulerAngles.y;
 //wantedHeight = target.position.y + height;
 wantedDistanceZ = target.position.z - distance;
 wantedDistanceX = target.position.x - distance;
 
 currentRotationAngle = transform.eulerAngles.y;
 //currentHeight = transform.position.y;
 currentDistanceZ = transform.position.z;
 currentDistanceX = transform.position.x;
 

 // Damp the rotation around the y-axis
 currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
 
 // Damp the distance
 //currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * //Time.deltaTime);
 currentDistanceZ = Mathf.Lerp(currentDistanceZ, wantedDistanceZ, distanceDampingZ * Time.deltaTime);
 currentDistanceX = Mathf.Lerp(currentDistanceX, wantedDistanceX, distanceDampingX * Time.deltaTime);

 // Convert the angle into a rotation
 currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
 
 // Set the new position of the camera
 transform.position -= currentRotation * Vector3.forward * distance ;
 transform.position.x = currentDistanceX;
 transform.position.z = currentDistanceZ; 
 //transform.position.y = currentHeight;
 
 // Make sure the camera is always looking at the target
 LookAtMe();
 }


 function LookAtMe(){
     //check  whether we want the camera to be smoothed or not - can be changed in the Inspector
     if(smoothed)
      {
         //Find the new rotation value based upon the target and camera's current position.  Then interpolate
         //smoothly between the two using the specified speed setting
         var camRotation = Quaternion.LookRotation(target.position - transform.position);
         transform.rotation = Quaternion.Slerp(transform.rotation, camRotation, Time.deltaTime * camSpeed);
     }
     //This default will flatly move with the targeted object
     else{
         transform.LookAt(target);
     }
 }

 @script AddComponentMenu("Player/Smooth Follow Camera")

*edit

and yes it is a child of the an object becuase i wanted it to rotate with the player while it is looking at it

Comment
Add comment · Show 3
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 robertbu · Aug 20, 2013 at 06:04 AM 0
Share

The camera does not reorient itself, so it is something being done by code somewhere. If you post your code, someone on this list might be able to help. Note if you are believing the camera is being reoriented based on angle changes in the Inspector, then the issue is likely the a change in Euler angle representation, not any real rotation.

avatar image Polantaris · Aug 20, 2013 at 06:06 AM 0
Share

Is your camera a child of something? I did that myself to experiment and it made it so that any changes to the adult screws around with the camera big time, because the camera's position and rotation become relative to the thing it is the child of, ins$$anonymous$$d of the Scene.

avatar image robertbu · Aug 20, 2013 at 09:51 PM 0
Share

I'm not sure under what situation you are having trouble, but I strongly suspect this is a eulerAngles issue. eulerAngles are not stored by Unity. When you set eulerAngles, they are converted to a Queaternion. When you read back the value, it is converted from the Queaternion back to an Euler angle representation. And that representation is not necessarily the same as the one set. For example execute this code:

 transform.eulerAngles = Vector3(180,0,0);
 Debug.Log(transform.eulerAngles);

The result will be (0,180,180). So for example if you are allowing the object this script is attached to rotate to 180 on the 'x' axis, you can see how reading eulerAngles.y on line 23 will not produce the value the code above is expecting.

0 Replies

· Add your reply
  • Sort: 

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

16 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

Related Questions

Line problem 0 Answers

Player camera targeting/locking another object 0 Answers

Enable the OrbitCam script how can I make it will continue from the current camera view and position ? 0 Answers

Calibrating Accelerometer Values 1 Answer

Camera gets stuck when cursor is locked 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