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 /
  • Help Room /
avatar image
0
Question by DarshGupta · Jan 20 at 06:31 AM · camera-movementcamera followcar gameracing gamejittering

[SOLVED] Camera severly jittering

I have a project in which the terrain has lots of trees, lots of detail meshes and post processing applied is on the camera. It is kind of a racing game that I am making. The camera appears to severely jitter on this terrain, however if I import the car prefab, apply the scripts and everything on a completely fresh and plain terrain in another scene, there isn't even a hint of jitter.

Why does this happen and how do I solve it? Please help!

Car Controller script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class CarController : MonoBehaviour
 {
     public Rigidbody sphereRB;
     public float speed;
     public float rotateForce;
     public LayerMask groundLayer;
     bool isCarGrounded;
     float moveInput;
     void Start ()
     {
         sphereRB.transform.parent = null;
     }
     void Update ()
     {
         moveInput = Input.GetAxisRaw("Vertical");
         moveInput *= speed;
         Debug.Log(moveInput);
         transform.position = sphereRB.transform.position;
         if (Input.GetAxis("Vertical") != 0 && Input.GetAxis("Horizontal") != 0)
         {
             foreach( TrailRenderer trail in GetComponentsInChildren<TrailRenderer>())
             {
                 trail.emitting = true;
             }
         } else
         {
             foreach (TrailRenderer trail in GetComponentsInChildren<TrailRenderer>())
             {
                 trail.emitting = false;
             }
         }
     }
     void FixedUpdate ()
     {
         RaycastHit hit;
         isCarGrounded = Physics.Raycast(transform.position, -transform.up, out hit, groundLayer);
         transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
         if (isCarGrounded)
         {
             sphereRB.transform.Rotate(0f, rotateForce * Input.GetAxis("Horizontal"), 0f);
             transform.Rotate(0f, rotateForce * Input.GetAxis("Horizontal") * Input.GetAxis("Vertical"), 0f);
             sphereRB.AddForce(transform.forward * moveInput, ForceMode.Acceleration);
         }
     }
 }

Camera follow script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class CameraFollow : MonoBehaviour
 {
     public Transform camPosTarget;
     public Transform camLookTarget;
     void FixedUpdate()
     {
         transform.LookAt(camLookTarget);
         transform.position = Vector3.Lerp(transform.position, camPosTarget.position, 10f * Time.deltaTime);
     }
 }


Comment
Add comment · Show 3
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 andrew-lukasik · Jan 21 at 10:34 AM 0
Share

Issues like this one are often invisible for fps >30, and especially >60. I'm willing to bet money on that the difference between those 2 situations you describe is framerate

First step when fixing anything here is to figure out how to reliably reproduce the problem, so it can be isolated. This simple script will help:

 using System.Threading;
 using UnityEngine;
 public class MainThreadThrottle : MonoBehaviour
 {
     [SerializeField][Range(0,100)] int _sleepMilliseconds = 0;
     void Update () => Thread.Sleep(_sleepMilliseconds);
 }

Try throttling your CPU and see if this problem is visible around 30 fps.

avatar image DarshGupta andrew-lukasik · Jan 21 at 12:48 PM 0
Share

@andrew-lukasik My game's running at 50 FPS $$anonymous$$imum. That can't be the problem. The jittering is very noticeable and annoying.

avatar image andrew-lukasik DarshGupta · Jan 21 at 02:15 PM 0
Share

It's not that these physics-rendering synchronization/interpolation issues does not exist at high framerates, it is that those are more apparent under low fps (because delta time is larger, so motion steps as well)

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DarshGupta · Jan 21 at 01:39 PM

I got it! All I had to do was move this line of code -

transform.position = sphereRB.transform.position

and these lines of code -

sphereRB.transform.Rotate(0f, rotateForce * Input.GetAxis("Horizontal"), 0f);

transform.Rotate(0f, rotateForce * Input.GetAxis("Horizontal") * Input.GetAxis("Vertical"), 0f);

in the CarController script to the FixedUpdate() method.

All the jittering is gone!

However, I don't quite understand why. I know that FixedUpdate runs more frequently than Update, but when I was seeing the car and sphere in the scene view, by putting those lines of code in FixedUpdate, it seemed like the car was trying to catch up with the sphere while the sphere was moving. In Update, it seems like the car is at the same position as the sphere.

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

139 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

Related Questions

How to smooth change to a different camera position when still following the player?,How to smooth change my camera position when still following the player? 0 Answers

How do i keep the camera at a fixed position without rotating with the mesh 0 Answers

Why does my tilemap shoot off into the distance when trying to track the player? 0 Answers

Problem with movement of camer 0 Answers

Camera bounds with zoomable camera 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