• 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 /
  • Help Room /
avatar image
0
Question by Kythosyer · Jul 15, 2016 at 08:13 PM · c#rotationmovementfps

Issue with wave-like motion when rotating with mouse input

I have encountered a rather odd issue with my program.

(To the moderators, I'm not sure if t$$anonymous$$s is in the right space, if it isn't, please do move it)

The setup:

In my scene, I have a GameObject w$$anonymous$$ch I have set as my player/character for t$$anonymous$$s game. The player/character has a c$$anonymous$$ld GameObject, w$$anonymous$$ch is a cube, w$$anonymous$$ch represents the head, and is a c$$anonymous$$ld via the $$anonymous$$erarchy. It also has a body for the character(both of these are just c$$anonymous$$ldren of the main c$$anonymous$$ldren/character).

When I move the mouse, rotation of the head should follow where the mouse is(the mouse is $$anonymous$$dden, so it relies on mouse input). If the movement around the y-axis is larger than a set amount, the body of the character should turn as well. I have t$$anonymous$$s all working fine.

The problem occurs with the actual movement. In certain circumstances, it will create a wave-like movement, w$$anonymous$$le still following the mouse

Ie. if I move the mouse vertically, then back to being "flat", then move it horizontally(without any y-movement), it will create a wave movement horizontally. The same occurs with the other rotation, where if I move the mouse horizontally first, then move it up and down, it will create a wave, but only in the up/down movement.

Gyazo for GIF demonstrating issue

In the GIF above, I move the mouse slightly upwards, then left and right. The "wave-like" movement can clearly be seen, as it moves to the left, and to the right.

T$$anonymous$$s is my code:

 void moveView()
 {
     //T$$anonymous$$s method is called every Update(), after a method that locks the cursor using
     //Cursor.lockState = CursorLockMode.Locked, then sets it to Cursor.visible = false;
     //Here are the raw inputs, the sensitivities are ySen and xSen, and are public floats.
     toRotOnY = Input.GetAxisRaw("Mouse X") * xSen;
     toRotOnX = Input.GetAxisRaw("Mouse Y") * ySen;
     //I t$$anonymous$$nk its here, but I'm not sure exactly what the *= operator does to Quaternions. Also, the init values are set in Start()
     targetRotHead *= Quaternion.Euler(-toRotOnX, toRotOnY, 0f);
     //The 0f in the Z feild is to lock rotation to x/y only.
     //Should body rotate to match head?
     if (t$$anonymous$$s.transform.eulerAngles.y >= targetRotHead.eulerAngles.y + 10 || t$$anonymous$$s.transform.eulerAngles.y <= targetRotHead.eulerAngles.y - 10)
     {
     //If the body should rotate, do it here
         t$$anonymous$$s.transform.rotation = Quaternion.Slerp(t$$anonymous$$s.transform.rotation, Quaternion.Euler(0f, targetRotHead.eulerAngles.y, 0f), moveSpeed);
        
     }
     //Rotate to the wanted rotation
     //moveSpeed is a float w$$anonymous$$ch dictates the smoot$$anonymous$$ng.
     headWithCamera.transform.rotation = Quaternion.Lerp(headWithCamera.transform.rotation, Quaternion.Euler(targetRotHead.eulerAngles.x, targetRotHead.eulerAngles.y, 0f), moveSpeed);
  

 }
Comment
Add comment · Show 2
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 Lewwwer · Jul 16, 2016 at 09:19 PM 0
Share

Hello!

I guess targetRotHead is a Quaternion storing the rotations of the head. You outlined a part of your script where you written: targetRotHead *= Quaternion.Euler(-toRotOnX, toRotOnY, 0f); I would not recommend multiplying Quaternions. Insted try to convert them to Euler angles and add the rotation to them, or just simply store them as a Vector3 rotation and translate them to Quaternion when needed.

avatar image Kythosyer · Jul 17, 2016 at 07:52 PM 0
Share

@lewwwer Hey, I'm not overly knowledgable in quaternions/Euler angles as I am only a high school student. The majority of my knowledge comes from reading other scripts and research. May I ask if you could give me an example of what you suggested?
Thanks!

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.

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

202 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 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 sphere to the direction of movement 0 Answers

I want to stop movement of character while i call animation like Kick Jump Punch etc.. Please help 1 Answer

Question on rigidbody character rotating to the degree of input and then moving 0 Answers

trying to make a smooth rotation script 0 Answers

How to make a gameObject's Y rotation being another gameObjects' X rotation 1 Answer


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