Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ChaosRobin · Dec 29, 2021 at 04:56 PM · cameracamera-movementcamera rotate

Stop camera from stuttering when looking straight up or down

Hey, I'm using the new input system and I'm trying to get the right stick to control where the camera is looking, my games controls should allow the players camera to rotate freely in any direction (except z) including going upside down, but my code isn't working.

Whenever the x rotation of the camera tries to go above the X rotation 90 or below the X rotation -90, the camera rotation tries not to pass that 90 mark and resets itself to 90, and if it could do this without stuttering I would call it good and move on, but the effect it has now is unacceptable.

Here's what I wrote:

     void Update()
     {
         currentRotation = transform.localEulerAngles;
         Vector2 rotationInput = ungodlyControlsInputAsset.PlayerControls.RotateCamera.ReadValue<Vector2>();
         Debug.Log(rotationInput);
 
             float h = gamepadHorizontalSpeed * rotationInput.x;
             float v = gamepadVerticalSpeed * -rotationInput.y;
 
             currentRotation += new Vector3(v, h, 0f);
             transform.localEulerAngles = currentRotation; 
 
     }

I hope you can help!

Comment
Add comment · Show 4
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 ssmas · Dec 29, 2021 at 05:16 PM 1
Share

fixing this bug would be fine, but not optimise, I recommend you using cinemachine package, for third-person and FPS camera which is customizable and compatible with your input system profile. (Tip: for having new input system with cinemachine add CinemachineInputProvider component to your virtual camera) https://www.youtube.com/watch?v=ImuCx_XVaEQ&ab_channel=samyam

avatar image ChaosRobin ssmas · Dec 29, 2021 at 05:24 PM 0
Share

I do want to use cinemachine but i cant understand how this problem is happening or how to fix it, first I would like to get it working, understand why it wasn't working, then after all of my camera controls are working through the new input system, go back and implement cinemachine wherever possible. Thank you for this advice and link to more information.

avatar image ChaosRobin ssmas · Dec 29, 2021 at 07:30 PM 0
Share

after implementing the cinemachine tutorial you linked me, I'm still having the same problem when looking straight down. After reading this I believe what I'm experiencing is a Gimbal Lock problem, where my $$anonymous$$d is thinking that the rotations inside the transform in the inspector are reliable enough to run math on but the sorcery within Euler is not property represented by thinking in terms of transform.rotate. I believe the solution will ultimately come down to modifying my code through Quaternions but I don't understand how exactly to communicate my needs to the Quaternion operation yet. I'm going to keep working the problem.

avatar image CodesCove ChaosRobin · Dec 30, 2021 at 07:54 AM 1
Share

It's not recommended to read the rotation's current value from eulerAngles, editing it and setting back in this context. This is because the eulerAngles are always converted to/from the rotations internal Quaternion representation and these conversion are not always commutative (this is also noted in the Unity Documentation https://docs.unity3d.com/ScriptReference/Transform-localEulerAngles.html). Reading the value is also actually unnecessary.

You can just use transform.localRotation *= Qaternion.Euler(new Vector3(v, h, 0f)) to have the same effect. This is also gimbal lock proof way.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ssmas · Dec 30, 2021 at 05:35 AM

I checked your @ChaosRobin code in Unity. Everything worked fine. The only thing I doubted was your input, so I changed it to the old input for myself.

 public class CameraTest: MonoBehaviour
 {
     public float gamepadHorizontalSpeed;
     public float gamepadVerticalSpeed;

     Vector3 currentRotation = Vector3.zero;
     Vector2 rotationInput = Vector3.zero;
 
     void Update()
     {
         currentRotation = transform.localEulerAngles;
         rotationInput.x = Input.GetAxis("Mouse X");
         rotationInput.y = -Input.GetAxis("Mouse Y");
 
         Debug.Log(rotationInput);
 
         float h = gamepadHorizontalSpeed * rotationInput.x;
         float v = gamepadVerticalSpeed * -rotationInput.y;
 
         currentRotation += new Vector3(v, h, 0f);
         transform.localEulerAngles = currentRotation;
     }
 }

Check your Debog.log() in the console panel and also any error that may cause this malfunction.

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

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

Related Questions

Why Do I Have Camera Stutter? 1 Answer

Jerky 3rd Person Camera Following Movement and Rotation 0 Answers

camera movments fixed.. character controller without using character controller -.-' 2 Answers

3rd Person Orbit Camera in LOCAL Space 0 Answers

Rotate Camera to the object 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