• 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
Question by SomeRandomGuy · Jul 04, 2012 at 06:53 AM · cameralerpfollowchoppy

custom follow script choppy movement

Hi, I made a little follow script for a flying game and it works just fine, however camera movement gets rather choppy. I can lower the smooth parameter to make it less choppy, but doing so means the camera will follow way to slow. Does anyone know of a way to fix this choppyness?

Here's my current script:

 #pragma strict
 var player: GameObject;
 var target : Transform; //this is a node behind my aircraft, not the same as player...
 var oldPos: Vector3;
 var newPos: Vector3;
 var smooth: float = 5;
 
 function Awake()
 {
  player = GameObject.FindWithTag("Player");
  oldPos = transform.position;
  newPos = target.position;
 }
 
 function LateUpdate()
 {
     oldPos = transform.position;
     transform.rotation = player.transform.rotation;
     transform.position = Vector3.Lerp(oldPos, newPos,Time.deltaTime * smooth);
  newPos = target.position;
 }
Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Tim-Michels · Jul 04, 2012 at 07:17 AM

You should smoothen your rotation too. The choppy effect probably comes from the fact that you're setting the rotation hard each frame.

Just use that Lerp with smoothing on your rotation too.

Example

transform.rotation = Quaternion.Lerp(transform.rotation, player.transform.rotation, Time.deltaTime * smooth);

Comment
SomeRandomGuy
Fattie

People who like this

2 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 SomeRandomGuy · Jul 04, 2012 at 07:58 AM 0
Share

Hmm, it seems that makes it slightly less choppy, tho it still is choppy. I'm assuming the target values of lerp are being reached before I update the positions etc. I'm going to try playing around with my smooth variable a bit more and see if that will make it more smooth without making it to slow.

EDIT: it seems that using the oldPos and newPos variables was the cause of the choppiness, using the values I assign to them directly in lerp seems to work way better.

EDIT: nevermind, just had my smooth value too low, was accidentally adjusting a different variable haha. still choppy D:

avatar image

Answer by Tim-Michels · Jul 04, 2012 at 08:41 AM

I would suggest something else for your position smoothing...

You can also do:

transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * smooth);

By further tweaking your smooth variable, combined with your rotation smoothing, you should get a better result.

Please let me know if that helped.

Comment
Fattie

People who like this

1 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 SomeRandomGuy · Jul 04, 2012 at 08:56 AM 0
Share

This is what I did, but I also changed newPos to target.position, as this seemed to make it a little smoother, is there any reason why you kept newPos the same, because to me using target.position seems smoother. This still is a bit choppy tho, and I can't have it follow any slower than it is right now, or the player will lose sight of the aircraft. I think I should have a way to slow down the camera when it gets close to the target position, much like quaternion.slerp for rotations

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Modified SmoothFollow 0 Answers

Object lerping in same direction as camera jitters 0 Answers

Unsmooth vehicle-following camera 1 Answer

3rd Person Camera Problem 1 Answer

Lerping Field Of View is buggy 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