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 /
This question was closed Aug 08, 2019 at 01:37 PM by jxng1 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by jxng1 · Aug 07, 2019 at 07:39 AM · camera3dlookatcamera followjitter

Jittering Camera 3D ,Jittery 3D camera using a LookAt() on an object

I have a simple project that I'm working on for school coursework and I'm using a LookAt() at the object. However, when I rotate move the camera the object jitters horribly. I've looked on the forums and tried solutions but I can't find anything. I'll post the code as well as the video. Thank you all for your time!

 public class CameraMovement : MonoBehaviour
 {
 // Start is called before the first frame update

 public Transform target;
 public float rotationSpeed;
 public float normalFOV;
 public float zoomedFOV;
 public int smooth;   

 void Start()
 {
     normalFOV = 100f;
     zoomedFOV = 10f;
     rotationSpeed = 10f;
     smooth = 5;
     this.GetComponent<Camera>().fieldOfView = normalFOV;
 }

 // Update is called once per frame
 void FixedUpdate()
 {

     transform.LookAt(target);
     if (Input.GetMouseButton(1))
     {
         MouseRotation();
     };
     MouseZoom();      
     
 }

 private void MouseRotation()
 {
     Vector3 cameraV = new Vector3(
         Input.GetAxis("Mouse X"),
         Input.GetAxis("Mouse Y")
         );
     
     transform.Translate(cameraV * Time.deltaTime * rotationSpeed);
 }

 private void MouseZoom()
 {
     if (Input.GetAxisRaw("Mouse ScrollWheel") > 0f && this.GetComponent<Camera>().fieldOfView != zoomedFOV)
     {
         this.GetComponent<Camera>().fieldOfView -= smooth;
     }
     if (Input.GetAxisRaw("Mouse ScrollWheel") < 0f && this.GetComponent<Camera>().fieldOfView != normalFOV)
     {
         this.GetComponent<Camera>().fieldOfView += smooth;
     }
     }

Video Link

,I have this simple camera that I use to focus on an object. However, every time I do rotate it, it causes really jittery camera movement. I will paste the code I've used for the camera below.

 public class CameraMovement : MonoBehaviour
 {
 // Start is called before the first frame update

 public Transform target;
 public float rotationSpeed;
 public float normalFOV;
 public float zoomedFOV;
 public int smooth;   

 void Start()
 {
     normalFOV = 100f;
     zoomedFOV = 10f;
     rotationSpeed = 10f;
     smooth = 5;
     this.GetComponent<Camera>().fieldOfView = normalFOV;
 }

 // Update is called once per frame
 void FixedUpdate()
 {

     transform.LookAt(target);
     if (Input.GetMouseButton(1))
     {
         MouseRotation();
     };
     MouseZoom();      
     
 }

 private void MouseRotation()
  {
     Vector3 cameraV = new Vector3(
         Input.GetAxis("Mouse X"),
         Input.GetAxis("Mouse Y")
         );
     
     transform.Translate(cameraV * Time.deltaTime * rotationSpeed);
 }

 private void MouseZoom()
 {
     if (Input.GetAxisRaw("Mouse ScrollWheel") > 0f && this.GetComponent<Camera>().fieldOfView != zoomedFOV)
     {
         this.GetComponent<Camera>().fieldOfView -= smooth;
     }
     if (Input.GetAxisRaw("Mouse ScrollWheel") < 0f && this.GetComponent<Camera>().fieldOfView != normalFOV)
     {
         this.GetComponent<Camera>().fieldOfView += smooth;
     }
 }
 }


I will also attach a video to demonstrate the problem.

Video Link

Thank you very much for your time and I tried to search the forums but I couldn't find anything to help me, I had already tried to use FixedUpdates etc, it may be just that the code isn't really optimum. Again, thank you very much!

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 DCordoba · Aug 07, 2019 at 06:14 PM 3
Share

honestly, common problem, happens everytime I did a camera follower, because update frame by frame is "seen" by human eye, get why happen each time, is a travel so, start, change

 void FixedUpdate(){

to

 void LateUpdate(){

check if this $$anonymous$$imize the jittering

and (off the question) to $$anonymous$$ouseRotation I suggest to use the RotateAround method

 transform.RotateAround(target.position, target.up,  Input.GetAxis("$$anonymous$$ouse X")* rotationSpeed);
 transform.RotateAround(target.position, target.right,  Input.GetAxis("$$anonymous$$ouse Y")*rotationSpeed); 

to get a "circular camera panning" around the target

avatar image jxng1 DCordoba · Aug 08, 2019 at 01:19 PM 0
Share

Thank you I'll try what you've said later when I get home.

avatar image jxng1 jxng1 · Aug 08, 2019 at 01:37 PM 0
Share

Works completely, wow. Thank you for your time and now I know how to use the camera!

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

193 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

Related Questions

How can camera smoothly follow a jerky game object? (bouncing up and down) 1 Answer

How to make slight Camera move and smooth 0 Answers

Camera Shake Effect When Camera Following Player 1 Answer

Adjusting camera so the whole level is visible 0 Answers

2D Camera Follow - Jittery? 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