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 smirlianos · Aug 07, 2014 at 12:03 PM · lerpsmoothdamping

Lerp has some bumping effect

Hello,

I took this script from the unify wiki, that it is supposed to smooth the movement of the camera. I wanted to follow a race car, but when he car moves, the camera is a bit bumpy. How can I fix that?

 var target : Transform;
 var distance = 3.0;
 var height = 3.0;
 var damping = 5.0;
 var smoothRotation = true;
 var rotationDamping = 10.0;
 
 function Update () {
     var wantedPosition = target.TransformPoint(0, height, -distance);
     transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
 
     if (smoothRotation)
     {
         var wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
         transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
     }
 
     else transform.LookAt (target, target.up);
 }
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

1 Reply

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

Answer by Dzoni94 · Aug 07, 2014 at 12:08 PM

Vector3.Lerp and Quaternion.Slerp interpolate between two values based on the value being the last parameter. Setting that value to 1 will be the same as not using Lerp/Slerp at all. If the camera is "bumpy" in your case, the issue might be the value set is too close to 1, which makes the camera get to target position/rotation too fast. Try reducing the damping and rotationDamping based on "bumpiness" in position/rotation of the camera.

Also, what might be the issue. The car is probably moved by a code in another script which is also executed in Update or FixedUpdate function. Positioning the camera should be done AFTER all the car positioning has been done, so you should change the Update to LateUpdate in this script. That will make sure the camera is trying to chase the new, correct, position of the car, rather than chase the old/current/new position, based on the execution order of the scripts.

Comment
Add comment · Show 12 · 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 smirlianos · Aug 07, 2014 at 12:13 PM 0
Share

It stops being bumpy from values < 1.0 but then, the camera gets too far from the car

avatar image smirlianos · Aug 07, 2014 at 12:24 PM 0
Share

If I change to LateUpdate, it is even more bumpy! This is the script I use to move the car

 #pragma strict
 var speed : float;
 var maxSpeed : float;
 var turnSpeed : float;
 
 function Start () {
 
 }
 
 function FixedUpdate () {
     var v = transform.forward;
     v.y = 0.0;
     v.Normalize();
     v *= Input.GetAxis("Vertical") * speed * Time.deltaTime;;
     v.y = rigidbody.velocity.y;
     rigidbody.velocity = v;
     transform.Rotate(0,turnSpeed * Input.GetAxis("Horizontal"),0);
 }
avatar image smirlianos · Aug 07, 2014 at 12:30 PM 0
Share

I did, check my comment

avatar image HarshadK · Aug 07, 2014 at 12:40 PM 1
Share

You are directly setting the velocity of the rigidbody.

Since FixedUpdate runs at a fixed time interval the change in velocity is at a constant rate.

As always stated, perform physics inside FixedUpdate.

avatar image Dzoni94 · Aug 07, 2014 at 12:44 PM 1
Share

FixedUpdate gets executed in fixed time intervals. Setting both camera and car function to FixedUpdate makes them execute the same number of times per second which gets them synced. Although you shouldn't do anything not physics related in FixedUpdate ( it doesn't mean it's impossible, just not advised ), and it's a good thing to only move the camera in LateUpdate after all other calculations are done so it renders stuff corectly.

Show more comments

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

22 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

Related Questions

How you change another script value smoothly on trigger 0 Answers

moving between two points over time 1 Answer

How can I smooth out the crouch movement? 1 Answer

Smooth Mouse Orbit c# 2 Answers

Smooth Camera/Object Movement 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