Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 D43DB33F · May 28, 2017 at 01:46 PM · camerafollowchoppy

Unsmooth vehicle-following camera

Hello,

I have written a smooth vehicle-following camera, but for some reason, it is shaky, like it was not updated often enough.

I've read several questions about this. Some people suggest to use LateUpdate() instead of Update(). I did this, but the problem remains. Some other people suggest to use FixedUpdate(). I tried that too, and it worked, but I'm afraid using FixedUpdate() is only hiding the problem without actually fixing it.

I saw in the scene view that the car itself was shaky, not the camera. Also when I drive, everything around me (objects, shadows, etc) are moving (relatively to the camera) smoothly. It's only the followed vehicle itself that is shaky (relatively to the camera only). I tried using a simple sphere instead of a complete car instead to make sure the complexity of the car model wasn't causing this, but I had the same problem. So I'm not sure about what is wrong.

Here is my code :

 using UnityEngine;
 
 public class RaceCameraController : MonoBehaviour
 {
     /// <summary>
     /// Vehicle to look at.
     /// </summary>
     [Tooltip("Vehicle to look at.")]
     public GameObject car;
 
     /// <summary>
     /// X rotation angle of the camera, relatively to the vehicle.
     /// </summary>
     [Tooltip("X rotation angle of the camera, relatively to the vehicle.")]
     public float lookXAngle;
 
     /// <summary>
     /// Position the camera tries to reach progressively, relatively to the vehicle.
     /// </summary>
     [Tooltip("Position the camera tries to reach progressively, relatively to the vehicle.")]
     public Vector3 carRelativeTargetPosition;
 
     /// <summary>
     /// Duration, in seconds, it would take the camera to reach its target position if the vehicle
     /// immediately stopped.
     /// </summary>
     [Tooltip("Duration, in seconds, it would take the camera to reach its target position if the vehicle immediately stopped.")]
     public float repositioningDuration;
 
     void LateUpdate()
     {
         Vector3 targetPosition = car.transform.TransformPoint(carRelativeTargetPosition);
         Quaternion targetRotation = car.transform.rotation * Quaternion.Euler(lookXAngle, 0f, 0f);
         float progress = Mathf.Min(Time.deltaTime / repositioningDuration, 1.0f);
         transform.position = Vector3.Lerp(gameObject.transform.position, targetPosition, progress);
         transform.rotation = Quaternion.SlerpUnclamped(transform.rotation, targetRotation, progress);
     }
 }

Do you have any idea about what could be wrong ? Thanks.

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 toddisarockstar · May 29, 2017 at 06:07 AM 0
Share

two things you could try. On the car's rigidbody. Try changing the interpolate setting. also try to use a character controller if you allready have not.

1 Reply

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

Answer by Namey5 · May 30, 2017 at 06:13 AM

FixedUpdate isn't hiding the problem, it is the actual (documented) fix. Physics in Unity runs in a different time frame to the normal Update call. Unity's alternative to make adjustments line up with physics calculations is to use FixedUpdate, that is its purpose.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html

Comment
Add comment · Show 4 · 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 D43DB33F · May 30, 2017 at 07:43 AM 0
Share

Thanks for your help ! I used LateUpdate in the first place because the documentation says that :

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

(here : https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.LateUpdate.html)

So for what reason exactly is FixedUpdate the right solution ? Thanks.

avatar image Namey5 D43DB33F · May 30, 2017 at 07:57 AM 0
Share

If you want more detail about it, basically it's down to the way the physics engine is updated. In Unity, to save resources this isn't done every Update (every frame), ins$$anonymous$$d it's done every Fixed Update (hence the name). The Fixed Update is controllable for accuracy reasons, meaning you can change how frequently it is called, and therefore how smooth physics objects are updated. It also means that a drop in frame rate will not alter the movement of a physics object, as the time between each Fixed Update is always the same, but the time between each Update may change.

There is a fairly simple explanation in the video in this tutorial.

https://unity3d.com/learn/tutorials/topics/scripting/update-and-fixedupdate

avatar image D43DB33F Namey5 · May 30, 2017 at 09:52 PM 0
Share

Thanks, but I still don't understand the reason of this unsmoothness. FixedUpdate is likely to be called more often than Update, fine, but this doesn't tell me why the camera looks so unsmooth. I'm running the game with 80 FPS, that's more than my screen can display, so I should not be able to see the steps of the camera movements. Is there anything wrong with my calculations ?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

custom follow script choppy movement 2 Answers

camera follow an game object 0 Answers

Camera Border Follow 1 Answer

Smooth Follow Problem 1 Answer

Getting Camera to follow falling Dominoes 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