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
0
Question by ForgeStudios · Aug 04, 2014 at 03:13 AM · c#cameraglitch

Smooth camera follow seems to be a bit choppy

So I wrote this custom 2D smooth camera follow script, but as soon as the camera is supposed to follow the player object the player object its self seems to jerk around. This is a visual effect and not a product of the script i'm using to actually move the character, I am sure of that.

My best guess is that something is causing the camera to interpolate between positions between frames, (I.E. the transform.position is being changed from zero to the position of the player), I cannot seem to locate the issue. So I turn to you! The script is below feel free to test it/keep it, but please help me find what is wrong.

 using UnityEngine;
 using System.Collections;
 
 public class cameraMechanics : MonoBehaviour {
 
     public float camDist, slugRate, slugFollowRate;
     public Transform mainObject;
     Vector3 camPos;
     Transform follow;
     
     void Start(){
         camPos = transform.position;
         follow = mainObject;
     }
     
     void Update(){
         float dist = Vector2.Distance((Vector2)camPos, (Vector2)follow.position);
         
         if(dist > slugRate){
             Vector2 cPS = (Vector2)camPos;
             cPS += ((Vector2)camPos - (Vector2)follow.position) * (slugFollowRate * dist);
             camPos = (Vector3)cPS;
         }
         
         camPos.z = camDist;
         
         transform.position = camPos;
     }
 }
 

Thank you in advance for any advice or help!

Comment
Add comment · Show 1
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 ForgeStudios · Aug 06, 2014 at 02:20 AM 0
Share

Update: The jitter problem only occurs with the object that is controlled with the character controller, essentially anything moved with regular controls.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Issah · Aug 04, 2014 at 08:18 AM

Hello,

http://docs.unity3d.com/ScriptReference/MonoBehaviour.LateUpdate.html

" For example a follow camera should always be implemented in LateUpdate because it tracks objects that might have moved inside Update."

When you'r camera follow the transform.position in update, the value can be calculated at the wrong moment, between two frame like you say, try to put you'r following instruction in LateUpdate and your forces in FixedUpdate.

Hope it will help

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 ForgeStudios · Aug 04, 2014 at 11:19 AM 0
Share

Good suggestion, but moving the camera update to lateupdate and the controls to fixedupdate didn't seem to fix the problem.

avatar image Issah · Aug 04, 2014 at 01:31 PM 0
Share

Ok i hope you will find !

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

23 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

Related Questions

Camera to follow the player in the form of radius 1 Answer

How do you position an object relative to the camera? 0 Answers

C# FP_Camera not following Character Controller 0 Answers

Switching cameras Script error 0 Answers

Dramatic Camera effect with all physical gameobjects paused? 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