• 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 Harry64 · Jan 02, 2013 at 09:59 PM · rotationparentchildstartlocal

Help: Camera script sets Camera rotation always to World Rotation

I have a big Problem with my Mouse Look script.

I have set the PlayerController to rotate with the camera and the camera to follow the PlayerController. They have the same Parent.

Now if I start the game and the Parent is turned around the y axis 270° the camera turns itself back to the world rotation and in the camera transform tab its then set to 90°.... if I rotate the camera in the transform tab it goes back to the world rotation too....

I found the part in my code which causes this problem but I dont know how to fix it... I mark the part in my code.

please help.

 var playerBody : GameObject;
 var cameraOffset = 0.7;
 
 var lookSensitivity : float = 4;
 @HideInInspector
 var yRotation : float;
 @HideInInspector
 var xRotation : float;
 @HideInInspector
 var currentYRotation : float;
 @HideInInspector
 var currentXRotation : float;
 @HideInInspector
 var yRotationV : float;
 @HideInInspector
 var xRotationV : float;
 
 var lookSmoothDamp : float = 0.08;
 @HideInInspector
 var currentAimRacio : float = 1;
 
 private var headbobbing : Headbobbing_harry;
 
 function Awake()
 {
     playerBody = GameObject.Find("Player Body");
     headbobbing = GetComponent(Headbobbing_harry);
 }
      
 function LateUpdate()
 {
     yRotation += Input.GetAxis("Mouse X") * lookSensitivity * currentAimRacio;
     xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity * currentAimRacio;
 
     xRotation = Mathf.Clamp(xRotation, -90, 90);
     
     currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
     currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
 
 
 // this line sets the start rotation always to the world rotation....
     transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation , 0);
 
 
     transform.position = playerBody.transform.position + Vector3(0,cameraOffset,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 Harry64 · Jan 03, 2013 at 04:43 PM

I solved the problem! I am new to coding and so I did not understand why the transform.rotation.y here not worked. now I know it better. I tryed now transform.rotation.eulerAngles.y and it works. here is the code that I put into the function Awake to get it to work.

 function Awake()
 {
     playerAll = GameObject.Find("Player All");
     playerAllRot = playerAll.transform.rotation.eulerAngles.y;
     yRotation = playerAllRot;
     currentYRotation = playerAllRot;
 }
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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Why is a child object not rotating properly with parent? 1 Answer

First Person Camera not being child of the character/ Set child's rotation to global rotation 2 Answers

How do I have a Child tell a Parent to move without the Child itself moving 0 Answers

rotate parent object to straighten child object? 2 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