• 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
1
Question by Daphnis26 · Sep 15, 2013 at 05:29 AM · c#cameramovementchoppy

Choppy Camera Follow

Hi, I'm using a custom sidescroller script and am getting extremely choppy camera movement. I know many people have had t$$anonymous$$s issue, and I've been trying all kinds of suggestions with no luck. My script:

 void Start () 
     {
         origDist = distance;
     }
 
     void Update () 
     {
         if (target)
         {
             if (Input.GetKey(KeyCode.LeftControl))
                 distance = origDist * 5;
             else
                 distance = origDist;
 
             Vector3 targetPos = target.position + Vector3.up * extraHeight;
             targetPos.z = -distance;
             transform.position -= (transform.position - targetPos) * 0.25f;
             
         }
     }

I've tried FixedUpdate and LateUpdate as well. How can I get t$$anonymous$$s script to smoothly follow a normal character controller? Thanks!

Comment
Add comment · Show 6
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 vexe · Sep 15, 2013 at 05:35 AM 0
Share

This attached to your camera right?

avatar image Daphnis26 · Sep 15, 2013 at 05:38 AM 0
Share

Yes it is.

avatar image vexe · Sep 15, 2013 at 05:39 AM 0
Share

A quick and easy way to make your camera follow the player, is to make the camera a child of your player object, set the distance manually. Does that work for your needs?

alt text

grav.png (3.0 kB)
avatar image Daphnis26 · Sep 15, 2013 at 05:45 AM 0
Share

Well it does fix the choppiness issue, but the script I have does more; it sets the camera to follow horizontally like a sidescroller. Parenting causes the camera to rotate with the character. I've been using this script with custom character scripts, but now I've decided to scrap those and build my character from scratch. The previous character scripts did not use a character controller and scripted it's own physics, but now I am using more standard assets...

avatar image Daphnis26 · Sep 15, 2013 at 05:57 AM 0
Share

YES! I kept Update, and set the time to 5.0 and it's silky smooth.

Show more comments

1 Reply

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

Answer by vexe · Sep 15, 2013 at 05:52 AM

Whenever you're doing any changes to positions inside Update, multiply by Time.deltaTime as that will make it time-dependent instead of frame-dependent.

  transform.position -= (transform.position - targetPos) * 0.25f * Time.deltaTime;

I know you've mentioned that you've tried the script in FixedUpdate, but give it a try...

Comment
Add comment · Show 3 · 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 Daphnis26 · Sep 15, 2013 at 06:00 AM 1
Share

Silky smooth, thanks for your help!

avatar image vexe · Sep 15, 2013 at 06:01 AM 1
Share

No problem, you're welcome :)

avatar image LieTR · Jan 31, 2014 at 04:35 AM 0
Share

I was struggling with this for a while too. The vexe answer was choppy when I used his code verbatim, but silky smooth when I put it in FixedUpdate().

 transform.position -= (transform.position - targetPos) *0.25;

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

How to use Android Accelerometer(Left and right tilt) to turn a sphere object and camera in that direction? 1 Answer

I need help to make the player go towards where the camera is facing. 1 Answer

[Solved it] Disable Camera Movement on Pause (C#) 1 Answer

Character movement relative to the 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