• 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
0
Question by awplays49 · May 30, 2015 at 01:10 PM · jitter

Camera follow for top down is jerky

Hi,

i have a game im working on, and this has been an issue for too long and i dont know how to fix it.

if you make a top down camera view and attach this script to the player

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
 
     public float moveSpeed;
     private Vector3 mousePos;
     public Animator anim;
     private bool canWalk;
     
     void Update () {
         mousePos = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y - transform.position.y));
         transform.LookAt (new Vector3 (mousePos.x, transform.position.y, mousePos.z));
         if (Vector3.Distance (transform.position, mousePos) >= 2.5f)
         {
             canWalk = true;
         }
         if (Vector3.Distance (transform.position, mousePos) <= 1)
         {
             canWalk = false;
         }
         if (canWalk == true)
         {
             if (Input.GetKey (KeyCode.W) && GameObject.Find ("Control Manager").GetComponent <ControlManager> ().moveEnabled == true)
             {
                 GetComponent <CharacterController> ().Move (transform.forward * moveSpeed * Time.deltaTime);
                 anim.SetInteger ("Direction", 1);
             }
             else
             {
                 anim.SetInteger ("Direction", 0);
             }
         }
         else
         {
             anim.SetInteger ("Direction", 0);
         }
         Vector3 playerXZ = new Vector3 (transform.position.x, Camera.main.transform.position.y, transform.position.z);
         Vector3 velocity = Vector3.zero;
         Camera.main.transform.position = Vector3.SmoothDamp (Camera.main.transform.position, playerXZ + Vector3.back * 3.75f, ref velocity, 0.05f);
         GetComponent <CharacterController> ().Move (Vector3.up * Physics.gravity.y * Time.deltaTime);
     }
 }
 

the camera jerks backwards like really jittery occasionally. please help:(

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 ThePersister · May 30, 2015 at 02:02 PM 0
Share

Just a quick dropby, but have you tried FixedUpdate ins$$anonymous$$d of Update? :)

avatar image awplays49 · May 30, 2015 at 02:57 PM 0
Share

You are a genius sir! :)

It completely slipped my $$anonymous$$d.

Thank you so much. $$anonymous$$aybe post as an answer and I'll accept it! :)

avatar image ThePersister · May 30, 2015 at 10:08 PM 0
Share

Anytime! Glad it worked, I put up an answer to accept. :)

1 Reply

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

Answer by ThePersister · May 30, 2015 at 10:07 PM

For most camera jitter related issues, FixedUpdate instead of Update is the answer. :)

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 awplays49 · May 30, 2015 at 10:48 PM 0
Share

Thanks! @ThePersister, can you look at my other question? It's about touch joysticks.

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

20 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

Related Questions

Trying to mix physics and direct movement without jitter 2 Answers

Camera Lerp Jitter 0 Answers

Is't impossible to move an object without jittering 2 Answers

Object jitters when camera is moving and is in the near? 0 Answers

Android 9 - Graphical freeze but scene runs in the background 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