• 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 SirPirelli · Apr 10, 2020 at 03:32 AM · rotationquaternionrotation axistransform.rotaterotations

Rotation changing in untouched axis

Somehow, when changing in x and y axis, z axis is also changed. I can't sleep because of this, I really cant understand the problem.

I tried the Transform.Rotate method and also by calculating the resulting quaternions to check if it was a bug with the method or something but the result is the same.

     Vector3 newHeadRotationDelta = Vector3.zero;
             newHeadRotationDelta += Vector3.up * xInput * mouseSensibility * Time.deltaTime;
             newHeadRotationDelta += Vector3.left * yInput * mouseSensibility * Time.deltaTime;

     var newQuat = headObj.localRotation * Quaternion.Euler(newHeadRotationDelta);
     headObj.localRotation = newQuat;

If someone can help me figure it out, I'd be much appreciated, this is driving me crazy.

Thanks

EDIT: Added more code for clarity

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 JustAbhi · Apr 10, 2020 at 05:35 AM

There is a very easy answer to your question. First make your camera in the scene a child of your player. Instead of changing the rotation of your player in both the axes just change Vertical rotation of your camera and the horizontal rotation of your Player separately.like:-

 void Update()
     {
         if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
             Cursor.lockState = CursorLockMode.None;
         transform.position = offset + plr.position;
         float y = Input.GetAxis("Mouse Y") * mousesensitivity * Time.deltaTime;
         float x = Input.GetAxis("Mouse X") * mousesensitivity * Time.deltaTime;
         xRotation -= y;
         xRotation = Mathf.Clamp(xRotation, -90f, 90f);
         transform.localRotation = Quaternion.Euler(xRotation, x, 0f);
         plr.Rotate(Vector3.up * x);
         
     }
     
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 SirPirelli · Apr 10, 2020 at 01:40 PM 0
Share

The resulting rotation is the same if I rotate separately the left and up vector or sum them and I dont want to just change the camera, I'm not even talking about cameras. I'm already just changing the localRotation of the object and any parent of the gameobject is rotating, so it cant be caused by a gameobject up in the hierarchy. I'll edit to add more code for clarity.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

163 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

Rotate Object Around Local X Axis , then Local Y Axis, then Local Z Axis (like a turtle) 0 Answers

How to find or compute or look for overall/max RPM by simply checking for rotation? 1 Answer

Quaternion LookRotation issue 0 Answers

Rotate to ground normal and steering direction for a Bicycle? 1 Answer

Rotation problem 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges