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 /
  • 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 this is in the right space, if it isn't, please do move it)

The setup:

In my scene, I have a GameObject which I have set as my player/character for this game. The player/character has a child GameObject, which is a cube, which represents the head, and is a child via the hierarchy. It also has a body for the character(both of these are just children of the main children/character).

When I move the mouse, rotation of the head should follow where the mouse is(the mouse is hidden, 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 this all working fine.

The problem occurs with the actual movement. In certain circumstances, it will create a wave-like movement, while 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.

This is my code:

 void moveView()
 {
     //This 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 think 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 (this.transform.eulerAngles.y >= targetRotHead.eulerAngles.y + 10 || this.transform.eulerAngles.y <= targetRotHead.eulerAngles.y - 10)
     {
     //If the body should rotate, do it here
         this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.Euler(0f, targetRotHead.eulerAngles.y, 0f), moveSpeed);
        
     }
     //Rotate to the wanted rotation
     //moveSpeed is a float which dictates the smoothing.
     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. $$anonymous$$ay 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.

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

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

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

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

transform.Rotate having no effect 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