Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Dec 20, 2020 at 06:06 PM by CyberModeSoftware for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by CyberModeSoftware · Dec 12, 2020 at 07:22 PM · camerarigidbodywheelcollidercamera follow

Why my camera is jittering?(Wheel colliders)

I have a big problem with camera follow , I tried all methods what I found on the internet in last 3 days , absolutely everything , but the problem is still the same.

(The camera is tracking the car)

Camera is jittering and makes small shakes.

Methods:

Change rigidbody interpolate Change Updates from camera and car controller Making another scripts Changing colliders Add Vector3.Lerp or Vector3.SmoothDamp Changing wheelcolliders parameters Reinstall unity and we are still there.

Do you have any idea what's going on?

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

  • Sort: 
avatar image
1
Best Answer

Answer by streeetwalker · Dec 12, 2020 at 07:53 PM

Yes, wheel colliders are finicky! Their springs oscillate even when it appears the car is at rest.

If you have parented the camera to the car that can be major problem. Your best bet is to not directly parent the camera.

If you are not, you can also set up your code so the camera does not move unless the motion of the car crosses some threshold, and also ignore the y axis if you do not have any vertical height on your track.

Here is a camera script I created I have had good luck with - maybe you can too, and modify it to your needs. You can use it with a fixed offset or control it using the mouse - just choose the options in the inspector. Set up the initial camera position relative to the car in the scene before you run the game:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
 
 // streetwalkers's camera follower modification
 public class CameraFollower : MonoBehaviour {
 
     [Header( "Target Parameters" )]
     public Transform target;
     public Vector3 offset;
     public float followSpeed = 2;
     public float lookSpeed = 3;
     public bool fixedCamera;
     public bool relativeCamera;
 
     private float distance;
 
     [Header( "Camera Rotation Speeds" )]
     public float y_sensitivity = 5f;
     public float x_sensitivity = 5f;
 
 
 
     // Other private variables
     private float pitch, yaw;
     private bool dragging = false;
 
     Vector3 c1Pos;
     Quaternion c1Rot;
 
     private void Start() {
         offset = transform.position - target.position;
         c1Pos = target.parent.position;
         c1Rot = target.localRotation;
     }
 
     void Update() {
         if( Input.GetMouseButtonDown( 2 ) ) {
             target.parent.position = c1Pos;
             target.localRotation = c1Rot;
             target.GetComponent<Rigidbody>().velocity = Vector3.zero;
         }
 
         transform.position = target.position + offset;
         if( Input.GetMouseButtonDown( 0 ) ) {
             dragging = true;
         }
 
         if( Input.GetMouseButtonUp( 0 ) ) {
             dragging = false;
         }
 
         pitch = 0;
         yaw = 0;
         if( Input.GetMouseButton( 0 ) && dragging ) {
             pitch = -Input.GetAxis( "Mouse Y" ) * y_sensitivity;
             yaw = Input.GetAxis( "Mouse X" ) * x_sensitivity;
         }
 
 
         float wheelDelta = Input.GetAxis( "Mouse ScrollWheel" );
 
         Zoom( wheelDelta );
         RotateAround();
     }
 
     private void FixedUpdate() {
         if( !relativeCamera ) {
             LookAtTarget();
             MoveToTarget();
         }
     }
 
     private void LookAtTarget() {
         Vector3 _lookDirection = target.position - transform.position;
         Quaternion _rot = Quaternion.LookRotation( _lookDirection, Vector3.up );
         transform.rotation = Quaternion.Lerp( transform.rotation, _rot, lookSpeed * Time.deltaTime );
     }
 
     private void MoveToTarget() {
         if( fixedCamera ) {
             transform.position = offset;
         } else {
             Vector3 _targetPos = new Vector3( target.position.x, 0, target.position.z ) +
                              target.forward * offset.z +
                              target.right * offset.x +
                              Vector3.up * offset.y;
 
             transform.position = Vector3.Lerp( transform.position, _targetPos, followSpeed * Time.deltaTime );
         }
     }
 
     private void Zoom( float wheelDelta ) {
         if( Mathf.Abs( wheelDelta ) > 0 ) {
             Vector3 direction = offset;
             distance = direction.magnitude;
             direction = direction.normalized;
             distance = distance - wheelDelta;
             offset = direction * distance;
         }
     }
 
     private bool RotateAround() {
         bool rotated = false;
 
         if( Mathf.Abs( pitch ) > 0 ) {
             offset = Quaternion.Euler( new Vector3( pitch, 0, 0 ) ) * offset;
             rotated = true;
         }
 
         if( Mathf.Abs( yaw ) > 0 ) {
             offset = Quaternion.Euler( new Vector3( 0, yaw, 0 ) ) * offset;
             rotated = true;
         }
         if( relativeCamera ) transform.LookAt( target );
         return rotated;
     }
 
 
     private float RotToDeg( float rot ) {
         float deg = 0;
         if( rot > 180f ) {
             deg = rot - 360f;
         } else {
             deg = rot;
         }
         return deg;
     }
 
 }



note that in this script the target was the car body that was a child of a parent rigidbody that the wheels were also attached to, so you may need to modify the code so it targets the correct object in your scene.

Comment
Add comment · Show 6 · 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
avatar image CyberModeSoftware · Dec 12, 2020 at 10:18 PM 0
Share

@streeetwalker Thank you very much for your answer but my game is for mobile and I did a test with your script but I have the same problem

https://we.tl/t-Lf8eNgo0Yr thats the video with my problem(with my script)

As you can see is shakeing to much . And my camera system is not a child for a car

Thank you for your reply.

avatar image CyberModeSoftware · Dec 12, 2020 at 10:53 PM 0
Share

Apparently it helps if you put the whole camera system to track the car and add in that system an empty game object for look at. Thats the reason why in the first person dosent jitter, because in first person is a different look at target

avatar image streeetwalker CyberModeSoftware · Dec 13, 2020 at 04:08 AM 0
Share

ahh - sorry yes, this is a third person camera. I think you are looking at two different problems:

1 has to do with the Update loop not matching FixedUpdate - you can see that for a moment, I think, in the overhead of the car when the car is moving towards the camera - you see a pretty extreme jitter in the car. If you haven't read this resource it may help you if that is part of the problem: https://www.kinematicsoup.com/news/2016/8/9/rrypp5tkubynjwxhxjzd42s3o034o8

  1. is the oscillation of the spring system as it goes over bumps, but that should have a $$anonymous$$imal effect a 3rd person camera if you are using code that does damping such as in the code of the one I posted.

avatar image CyberModeSoftware · Dec 13, 2020 at 12:17 PM 0
Share

Thank you very much for helping me with this problem which I finally managed to solve.

avatar image streeetwalker CyberModeSoftware · Dec 13, 2020 at 01:34 PM 0
Share

So what was the problem in the end?

avatar image CyberModeSoftware · Dec 13, 2020 at 07:55 PM 0
Share

Apparently it helps if you add an empty game object witch the camera can track, without tracking the position of the car with rigidbody, wheel colliders, ...

Follow this Question

Answers Answers and Comments

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

When attaching my custom camera script camera shakes when player starts to move fast. 1 Answer

When attaching my custom camera script camera shakes when player starts to move fast. 0 Answers

How Use rigidbody.MovePosistion With A Player Controlled Moving Camera 0 Answers

Help with setting up 2D auto scrolling camera using Cinemachine 1 Answer

Need help with camera in top down shooter 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