Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 qanh97 · Mar 25, 2019 at 08:14 AM · cameracamera-movementcamera followcamera movement

Smooth camera on moving platform

I have this script of camera controller which follow the player:

     public GameObject player;
     private float smoothness = 0.1f;
     private Vector3 offset;
 
     // Use this for initialization
     void Start () {
         offset = transform.position - player.transform.position;
     }
     
     // Update is called once per frame
     void FixedUpdate () {
         Vector3 desiredPosition = player.transform.position + offset;
         Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothness);
         transform.position = smoothedPosition;
     }

Normally it goes nicely and very smooth. However when the player object boards a moving platform, the camera stutters back and forth a little which cause image tearing. What should I add to make it smooth?
Here is the script to hold the player object on a moving platform which I suspect as the cause of the issue:

     private Vector3 offset;
     private GameObject target = null;
 
     private void Start()
     {
         target = null;
     }
 
     private void OnTriggerStay(Collider other)
     {
         target = other.gameObject;
         offset = target.transform.position - transform.position;
     }
 
     private void OnTriggerExit(Collider other)
     {
         target = null;
     }
 
     private void LateUpdate()
     {
         if(target != null)
         {
             target.transform.position = transform.position + offset;
         }
     }

Thank you in advance!

Comment
Add comment · Show 2
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 highpockets · Mar 25, 2019 at 08:28 AM 0
Share

Try making the player a child of the platform when he is grounded on the platform, and of course unparent when he is not grounded

avatar image qanh97 · Mar 26, 2019 at 02:46 AM 0
Share

If the player object become the child of the platform, it will not be able to control since the player object is a sphere that move by force. I used the "hold" method above so the player object can move freely on the platform while sticking on it ins$$anonymous$$d of always positioned at the center of the platform.

1 Reply

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

Answer by laurG · Mar 26, 2019 at 05:14 AM

Following @highpockets 's comment,: depending on the player controller script, it should be possible to move it even if it's the child of the platform, but that's not the issue here:

FixedUpdate is for physics, so the Camera script shouldn't use it. Change it to LateUpdate and it will work.

(FixedUpdate is called at fixed intervals, independent of the framerate, so if your deltaTime is lower than the Time.fixedTimeStep (usually 0.016~0.02) it means update is called more often so Camera will "lag" behind because of the FixedUpdate being called less often than Update/LateUpdate)

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 qanh97 · Mar 27, 2019 at 07:39 AM 0
Share

I changed it to LateUpdate/Update like you said. The camera now very smooth on the platform. However the player object now stutter when moving normally (I assume it is because of being controlled by physics/force). Anyway thank you for pointing out the problem!

avatar image qanh97 · Mar 27, 2019 at 08:41 AM 1
Share

Never$$anonymous$$d, I just forgot the rigidbody interpolate.

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

169 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a camera to Follow two players 2 Answers

Help make camera zoom smoother 3 Answers

How to make a camera Follow an Object moving in zigzag path? 1 Answer

Camera move & rotate along vehicle 0 Answers

camera follow gameobject moving in angular path. 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