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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Cinkokoko · Apr 30, 2012 at 10:12 AM · camerafixedupdateparentingjitter

Jitter Camera Effect When Parented To Animated Object

Heya, I was trying to fix this problem on my own for some time, but everything I tried failed so maybe someone can help me with solving that problem.

The thing is I have a Character Controller player who is changing its position and rotation in FixedUpdate() function. I have a moving platform ( cube, uniform scale ) and it has one Animation Clip attached which was made in Unity Animation Editor, and the only thing it does is moving the platform. When player stands on this animated moving platform, he is parented to it, so they can move together. Then at last I have Camera which also is calculated and translated + rotated at FixedUpdate() function to remove jitter effects.

And everything works great except when player is parented to this moving platform, when big jitter effect is shown.

Simpler Camera Script:

 protected void FixedUpdate()
 {
             transformFrom = _cameraTransform.position;
          transformTo = player.position + player.TransformDirection( 0,4,-8 );
         
         _cameraTransform.position = Vector3.Lerp( transformFrom, transformTo, Time.fixedDeltaTime * cameraMovementDamping );
         
         _cameraTransform.LookAt(player.transform.position);
     }

In my main script camera rotation is also smoothed with Quaternion.Lerp.

Problem Effect:

http://www.youtube.com/watch?v=1-8Zm3PG4y4

At the beginning the video is normal speed, then it slows to show you it in slow motion ( plus my Frame Rate of capturing dropped then ).

Thank in you advande for any kind of help :)

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

2 Replies

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

Answer by venkspower · Apr 30, 2012 at 11:37 AM

You don't have to calculate the position of or rotate the camera. You just have to child it, as the same way you did with the CharacterController. Make sure, you have made that through the code.

 var camera : GameObject;
 var platform : GameObject;
 function Update(){
 camera.transform.parent = platform.transform;
 }
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 Cinkokoko · Apr 30, 2012 at 12:12 PM 0
Share

Dunno why there was problem with my calculations, BUT your idea delete the jitter effects for now, so big Thumbs Up for you :)

avatar image Leocesar · Apr 24, 2013 at 09:09 PM 0
Share

The same thing was happening to me! When I parent the camera Gameobject through editor I get the jittering, but when I set the parent through code the jitter goes away, very strange thing indeed! I wonder if there is any difference between these two methods of parenting.

Tip: you need to parent only once in Start function and not in the Update function. Thank you venkspower for your answer!

avatar image
0

Answer by Kryptos · Apr 30, 2012 at 11:34 AM

Do not move the camera inside a FixedUpdate. There is no need for that. The pruprose of a camera is to shoot the scene, not playing physics.

Therefore, it is a good idea to fix the camera position juste before the scene is rendered.

Fortunately Unity provides juste the right event for that OnPreRender (edit: not the best solution, see below):

 void OnPreRender()
 {
     transformFrom = _cameraTransform.position;
     transformTo = player.position + player.TransformDirection( 0,4,-8 );

     _cameraTransform.position = Vector3.Lerp( transformFrom, transformTo, Time.deltaTime * cameraMovementDamping );

     _cameraTransform.LookAt(player.transform.position);
 }

If this doesn't work (I did not try it myself), you can still update the camera position in a latter phase using LateUpdate:

 void LateUpdate()
 {
     transformFrom = _cameraTransform.position;
     transformTo = player.position + player.TransformDirection( 0,4,-8 );

     _cameraTransform.position = Vector3.Lerp( transformFrom, transformTo, Time.deltaTime * cameraMovementDamping );

     _cameraTransform.LookAt(player.transform.position);
 }


edit: LateUpdate is the method to use. OnPreRender does not change position/rotation but can be used to set/unset effects such as fog.

Comment
Add comment · 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 Cinkokoko · Apr 30, 2012 at 11:58 AM 0
Share

There's a problem with it. The reason I changed Camera from Update/LateUpdate to Fixed Update is because when using Update it jitter in many cases, for example when free falling ( even if I use smoothed camera movement )

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Physics + first person camera = jitter? 4 Answers

Unity3d RTS style camera movement is jittery 0 Answers

Jittery Movement - specific mechanics in mind 0 Answers

Lerping orthographic camera size jitters 1 Answer

Particles lag/stutter - choppy movement 3 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