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 aderelha · Oct 13, 2020 at 05:35 PM · camerafpscamera rotatefps controller

Why is the Camera bouncing on the X-Axis?,Why does the Camera jump around on the X-Axis?

Hello,

I am new at Unity and after watching multiple tutorials, I created this script to make a smooth FPS-Cam:

     public class CamMovement : MonoBehaviour
 {
     private float MouseSensivity;
     public float MaxY;
     public float MinY;
     public Transform Bodytrans;
     float xRotation;
     float yRotation;
     public Slider SensivitySlider;
     public float SpinSpeed;
 
 private void Start()
     {
         Cursor.lockState = CursorLockMode.Locked;
         SensivitySlider.value = 100;
     }
 
 void SetSliderValues(){...}
 
 void CursorLock(){...}
 
 void CamRotate()
   {
 float mouseX = Input.GetAxis("Mouse X") * MouseSensivity *
 Time.deltaTime;
 float mouseY = Input.GetAxis("Mouse Y") * MouseSensivity *
 Time.deltaTime;
 
         xRotation -= mouseY;
         yRotation += mouseX;
         xRotation = Mathf.Clamp(xRotation, MinY, MaxY);
         Quaternion RotationY = Quaternion.Euler(xRotation,0, 0);
         Quaternion RotationX = Quaternion.Euler(0, yRotation, 0);
         transform.localRotation = Quaternion.Lerp(transform.localRotation, RotationY, SpinSpeed * Time.deltaTime);
         Bodytrans.rotation = Quaternion.Lerp(Bodytrans.rotation, RotationX, SpinSpeed * Time.deltaTime);
  }
 
 void Update()
    {
         CamRotate();
         CursorLock();
         SetSliderValues();
     }
 }

The Problem: The Cam keeps bouncing on the X-Axis when moving at fast speed. Example: I move the Cam to the right with high MouseSensivity. The mouse now bounces back to the left. This only occurs at high speed.

I have tried using Bodytrans.Rotate() instead of Quaternion.Lerp() first; This does remove the bouncing, but it also causes a weird stuttering, like the Camera is skipping frames. If Bodytrans.Rotate() is the right choice, how do you remove the stuttering?

Thanks in advance!

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
1
Best Answer

Answer by AbbottMedia · Aug 30, 2021 at 05:42 PM

Hey, sorry to bring up an old post but I was having the same problem and decided to reply in case others do too. I believe the bouncing happens because when x input value goes over 1 with a high multiplier (effectively sensitivity setting) unity takes it as a high rotation input (e.g. 390) and when it converts it into a quaternion it ends up ignoring the full rotation and trying instead to Lerp/Slerp to 30 (390 - 360). You end up getting it attempting and accelerating to lerp a full rotation then hitting it's target and bouncing off in the following frame.


As a solution I ended up clamping the amount of input you can have on the x axis. It makes it more sluggish to respond, and may not work well for an FPS, but keeps the camera from ping ponging.


 if (Input.GetMouseButton(0)) {
         xDeg += Mathf.Clamp(Input.GetAxis("Mouse X"), -0.99f, 0.99f) * xSpeed * moveSpeed;
         yDeg -= Input.GetAxis("Mouse Y") * ySpeed * moveSpeed;
         //Clamp the horizontal axis for the orbit
         xDeg = ClampAngle(xDeg, xMinLimit, xMaxLimit);
         //Clamp the vertical axis for the orbit
         yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
         OrbitCamera(xDeg, yDeg);
 } else {
         OrbitCamera(xDeg, yDeg);
 }


If someone else knows a better way to handle this, or if it's caused by something other than the vector3/quaternion conversion please let me know.

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

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

First Person Camera looking down 1 Answer

Problems with Dani's Karlson FPS Movement Controller 1 Answer

how to make my bones follow the camera(FPS) 0 Answers

FPS Camera Control rotation limits 1 Answer

Camera rotation on z axis 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