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 /
avatar image
2
Question by kag359six · Nov 23, 2012 at 05:37 PM · camerafollowjittersmoothdamp

smoothdamp causes jitters

I have a camera following a ball using the following code:

     public float smoothTime = 0.3f;
     private Vector3 velocity = Vector3.zero;
     
     public Transform ball;
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         
         Vector3 target = new Vector3(ball.position.x, ball.position.y + 3, transform.position.z);
         //transform.LookAt(ball);
         transform.position = Vector3.SmoothDamp(transform.position, target, ref velocity, smoothTime);
         
     }

Why do the objects that move in my scene jitter when i use the smoothdamp method? In the scene view it looks fine but in the game view it jitters a lot.

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

4 Replies

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

Answer by kag359six · Nov 24, 2012 at 03:46 PM

After further research I found the answer. The rigidbodies are not completely in snyc with the graphic updates so I had to put:

`body.interpolation = RigidbodyInterpolation.Interpolate;`

This makes the rigidbody in sync with the graphics, and prevents the jittery object effect when a camera smoothly follows it.

Comment
Add comment · Show 2 · 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 ragnaros100 · Nov 04, 2015 at 07:55 PM 0
Share

Just excactly did you do this? I'm sitting with the exact same problem as you. How'd you fix it? Where'd you put the interpolation code?

avatar image rlaine ragnaros100 · Aug 02, 2017 at 02:36 AM 0
Share

I put the code right after Rigidbody rb = GetComponent(); in my player controller. Solved the jitter problem for me!

avatar image
2

Answer by darthbator · Nov 24, 2012 at 12:27 AM

Try placing the code inside the LateUpdate method. Normally when you are tracking moving objects in the scene you'll want to make sure it's done doing it's movement in the frame before you track them.

Also is there a reason you're using smoothDamp? If you're tracking the object at a constant distance you should be able to just adjust the camera's position relative to the target without having to smooth the value.

Comment
Add comment · Show 1 · 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 kag359six · Nov 24, 2012 at 03:05 PM 0
Share

I use smoothDamp because i want the camera to slightly fall behind when the ball is moving ins$$anonymous$$d of it following its exact position all the time. And the LateUpdate didn't stop the jittering. Neither does Vector3.Lerp.

avatar image
0

Answer by frankslater · Jul 10, 2017 at 08:20 PM

Keep in mind that Physics and frames run independently. If you move objects with physics (including FixedUpdate()), you need to move your camera with physics (and/or in FixedUpdate()) otherwise you will get jitter. If you move everything on a per frame basis, you need to move your camera the same way (in Update()). If by any reason you must use both physics and frame based movement in your scene, that's when you can look at interpolation, otherwise you are just tolling on performance with it.

Give this code a try:

 public float smoothTime = 0.3f;
 private Vector3 velocity = Vector3.zero;
  
 public Transform ball;
  

 void FixedUpdate () {
     Vector3 target = new Vector3(ball.position.x, ball.position.y + 3, transform.position.z);
     //transform.LookAt(ball);
     transform.position = Vector3.SmoothDamp(transform.position, target, ref velocity, smoothTime);
 }
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
avatar image
0

Answer by dpami507 · Jul 24, 2020 at 03:37 AM

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GunPositionScript : MonoBehaviour
 {
     public Transform target;
     public float posSpeed;
     public float rotSpeed;
     public Vector3 velocity = Vector3.zero;
 
 
     void Start()
     {
 
     }
 
     private void Update()
     {
         Sway();
     }
 
     // Update is called once per frame
     void Sway()
     {
         gameObject.transform.position = Vector3.SlerpUnclamped(transform.position, target.transform.position, posSpeed * Time.deltaTime);
 
         gameObject.transform.rotation = Quaternion.Slerp(transform.rotation, target.transform.rotation, rotSpeed * Time.deltaTime);
     }
 }

I Found That this creates a smooth follow and I hope this helps!

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

15 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

Related Questions

2D Camera Smooth follow, FixedUpdate and LateUpdate odd difference, help needed. 1 Answer

Object lerping in same direction as camera jitters 0 Answers

2D Camera Follow - Jittery? 1 Answer

Third preson controller without camera controller !!! 1 Answer

How do I fix this jitter problem? 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