Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Izmail360 · Jan 25, 2018 at 11:59 AM · character controllermouse movement

Character Controller - rotation changes z axis

Hello, I am new to Unity and just trying to implement character controller. I do have a problem with move movement - where I am rotating vertical movement around x-axis and horizontal around y-axis. What I do not understand though is that also z-axis rotation is applied.

Here is my code:

 private void Rotate()
 {
     rotationX += rotateUD * SensitivityX;
     rotationY += rotateLR * SensitivityY;

     Quaternion quaternionX = Quaternion.AngleAxis(rotationX, Vector3.left);
     Quaternion quaternionY = Quaternion.AngleAxis(rotationY, Vector3.up);

     transform.localRotation = originalRotation * quaternionX * quaternionY;
     Debug.Log(quaternionY);
 }
 private void GetInputs()
 {
     moveLR = Input.GetAxis("Horizontal");
     moveFB = Input.GetAxis("Vertical");
     rotateUD = Input.GetAxis("Mouse Y");
     rotateLR = Input.GetAxis("Mouse X");
 }

If I debug quaterninX and quaternionY, both have z vector as 0. Therefore I am really confused. Thanks for hint.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by gordiri · Jan 25, 2018 at 12:16 PM

I think problew is the way how you rotate. originalRotation may have non zero z rotation and when you multiply you are getting non zero z as result. I suggest you to use Transform.Rotate( ) instead its much easier

Comment
Add comment · Show 5 · 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 Izmail360 · Jan 25, 2018 at 12:33 PM 0
Share

I checked that during initialization, the originalRotation has value "(0.0, 0.0, 0.0, 1.0)". I will try Transform.Rotate().

avatar image Izmail360 · Jan 25, 2018 at 12:37 PM 0
Share

I really do not understand. Even transform.Rotate(new Vector3(rotationX, rotationY, 0)); is giving me rotation along z-axis. Before I move with a mouse, z-rotation is zero.

avatar image gordiri Izmail360 · Jan 25, 2018 at 12:44 PM 0
Share

Try to set second parameter to Space.World

avatar image Izmail360 gordiri · Jan 25, 2018 at 12:51 PM 0
Share

It's the same result - z-axis rotation is still changing :(. Basically, whenever I remove one axis - either x or y, then z rotation is not applied. It's applied only, when x and y rotations are used.

Show more comments
avatar image
0

Answer by Izmail360 · Jan 26, 2018 at 07:27 AM

I made a progress, but it's still unclear to me. I have two coded. One works and second does not.

Working code (very simmilar to posted above):

     rotationX += Input.GetAxis("Mouse Y") * MovementSpeed;
     rotationY += Input.GetAxis("Mouse X") * MovementSpeed;

     Quaternion quaternionX = Quaternion.AngleAxis(rotationX, Vector3.left);
     Quaternion quaternionY = Quaternion.AngleAxis(rotationY, Vector3.up);

     transform.localRotation = originalRotation * quaternionY * quaternionX;

Bad code (rotates also around z-axis):

     rotationX = Input.GetAxis("Mouse Y") * MovementSpeed;
     rotationY = Input.GetAxis("Mouse X") * MovementSpeed;

     transform.Rotate(rotationX, rotationY, 0);

Can somebody explan the problem? It looks like I am missign some king of very basic.

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.

Follow this Question

Answers Answers and Comments

74 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

Related Questions

Colliders Not Working 1 Answer

Why is my character not flipping? 2 Answers

Why is my character controller cutting to an overview? 0 Answers

Code for - Rigidbody vs Character Controller 0 Answers

Framerate independent Movement 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