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
-1
Question by Anymeese · Mar 16, 2014 at 05:45 AM · lerpmathfmathf.lerp

How to Lerp for a number to get BIGGER instead of smaller?

I'm trying to write code that lerps the camera's rotation from where it currently is, to the player's facing angle. If the angle is less than 180, the lerp works fine. However if it's GREATER than 180, the code will still lerp the angle, but since the lerp value is getting smaller and smaller as it approaches 0 (the relative y rotation 0 means the camera is facing the same way as the player), it circles all the way around the player rather than just making the semi-circle

So right now, to get to 0, it's going

150...140...130...........20..10..0 AND 270...260...250........20..10..0

But I want it to go

150...140...130...........20..10..0, and 270...280...290........340..350..360 (360 == 0)

Here is my code:

 void Update()
 {
     if(isLerping)
     {
         float yVal;

         if(transform.eulerAngles.y < 180f)
             yVal = Mathf.Lerp(transform.rotation.eulerAngles.y, transform.parent.transform.rotation.eulerAngles.y, lerpSmooth * Time.deltaTime);
         else
             //(HOW???)

         transform.eulerAngles = new Vector3(transform.eulerAngles.x, yVal, transform.eulerAngles.z);

         if(transform.rotation.eulerAngles.y == transform.parent.transform.rotation.eulerAngles.y)
             isLerping = false;
     }
 }
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 tobyfee · Mar 16, 2014 at 06:20 AM 1
Share

not adding it as an 'answer' because it's just a guess, but might you not want to be using $$anonymous$$athf.LerpAngle ? http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$athf.LerpAngle.html

code example even seems to cover this use case...

avatar image Anymeese · Mar 16, 2014 at 08:00 AM 0
Share

This did it perfectly :) Didn't know this existed! Thanks :)

1 Reply

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

Answer by Anymeese · Mar 16, 2014 at 08:06 AM

tobyfee's answer was correct (use Mathf.LerpAngle)

Comment
Add comment · 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

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

20 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

Related Questions

Making an object bounce, using Mathf.Lerp 1 Answer

Trying to lerp in different states in a switch statement 0 Answers

How the heck does Mathf.Lerp work? 2 Answers

how to use time on lerp 2 Answers

Mathf.Lerp not working 2 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