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 MrCow · Feb 04, 2013 at 06:26 AM · androidlerpjerkymaincamera

Where should I Lerp (beginner).

I've been looking around and I've seen Lerp placed in Update and in LateUpdate. Trying to optimize my code but I'm new to this coding, Does it matter were I Lerp the position/rotation of a gameObject? Some guidance or a point in the right direction would be greatly appreciated.

The following code is from: http://www.cratesmith.com/archives/183 and http://answers.unity3d.com/questions/23566/how-to-get-an-object-to-follow-another-object-at-a.html

  • public void Update() {
    // Just interpolate values each frame
    currentTrajectory = SetTrajectory(Vector3.Lerp(currentTrajectory, updatedTrajectory,
    Time.DeltaTime*trajectoryBlend); }

  • function LateUpdate() { thisTransform.position.x = Mathf.Lerp( thisTransform.position.x, target.position.x + xOffset, Time.deltaTime smoothTime); thisTransform.position.y = Mathf.Lerp( thisTransform.position.y, target.position.y + yOffset, Time.deltaTime smoothTime);}

Here's a snippit of my code, its on the main camera.

void Update() {

     appliedSpeed = Time.deltaTime * damp;
 }
 
 void LateUpdate()
 {
     transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0,0,angle), appliedSpeed);
 }


I split them up because I thought one could be calculated a bit less then the other. Not sure if this is a good thing or if I should keep them both in the update function.

The reason why I'm asking is because when I build my game to an Android device (Galaxy S2/S3) it'll be running smoothly but then the camera will cut/jerk in a random direction, the problem isn't present when the game builds on my PC and I've got no idea why its doing it :[ Halp...

[3]: http://answers.unity3d.com/users/17442/mox.html

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
2
Best Answer

Answer by Doireth · Feb 04, 2013 at 07:46 AM

It's best to make changes to camera (if it's tracking or following an object) in LateUpdate().

The reason for this is say for example you have a camera following a player, in Update() the player movements are calculated and performed, then in LateUpdate() the camera performs it's movement/changes based on the new position of the player.

That way you'll get smooth movement because if the camera's changes were also made in Update() there's no guarantee that they'll be accurate as the camera may be adjusted before the player, leading to jerky movement in the next frame as it's now trying to catch up.

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 MrCow · Feb 04, 2013 at 04:33 PM 0
Share

Thank you very much ^___^

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

10 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

Related Questions

Lerping the Camera closes Nexus 5, not Nexus 10 0 Answers

Set Local Rotation of VR Camera Rig 1 Answer

Can anyone maintain smooth 60fps on Android (2D) ? 0 Answers

Control time transition between colors 1 Answer

How to move gameobject with touch on Android 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