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 MadJohny · Mar 01, 2014 at 09:28 AM · c#rotationpositionlerpmathf

Mathf.Lerp not working

Hi, I have been having this issue for a while now and finally decided to make a question about this since it's happenning in a lot of situations and not just only this one, the thing is, I can't get Mathf.Lerp to work, nor Vector3.Lerp, any kind of Lerp, I am trying to lerp the rotation of an object in the y axis. But I've been trying to do this in a lot of different situations, like lerping between two positions. The code just doesn't work.

this is the line of code, it is on LateUpdate:

 theRotation.y = Mathf.Lerp (transform.rotation.y, cameraTargetScript.currentYRotation, Time.deltaTime * rotateSpeed);

So, what am I doing wrong? Thanks in advance.

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

Answer by whydoidoit · Mar 01, 2014 at 09:38 AM

Well your problem there is that you are lerping a part of a quaternion which is not the y rotation you probably think it is.

    var someRotation = transform.eulerAngles;
    someRotation.y = Mathf.LerpAngle(someRotation.y, cameraTargetScript.currentYRotation, Time.deltaTime * rotateSpeed);
    transform.eulerAngles = someRotation;

Note use LerpAngle for angles as it goes the right way around (the shortest route). You have to put the rotation back into the transform and if you want actual degrees use eulerAngles not rotation.

Comment
Add comment · Show 3 · 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 whydoidoit · Mar 01, 2014 at 09:39 AM 0
Share

http://unitygems.com/quaternions-rotations-part-1-c/

avatar image MadJohny · Mar 01, 2014 at 09:57 AM 0
Share

Okay... now this is gettin weird, something seems to be wanting the rotation to snap back

avatar image MadJohny · Mar 01, 2014 at 10:06 AM 0
Share

Oh, I didn't read your script well, so it should also work, anyway just Lerp seems to be working fine

avatar image
0

Answer by SirCrazyNugget · Mar 01, 2014 at 09:54 AM

From the looks of your code Lerp isn't the function you're looking for.

Lerp interpolates between two values by a value between 0f and 1f. If you specify the two values from=60 and to=100 depending on the value given will return the interpolated value in between those two points.

so:

 Mathf.Lerp(60f, 100f, 0f); //return 60f

 Mathf.Lerp(60f, 100f, 0.25f); //return 70f

 Mathf.Lerp(60f, 100f, 0.5f); //return 80f

 Mathf.Lerp(60f, 100f, 0.75f); //return 90f

 Mathf.Lerp(60f, 100f, 1f); //return 100f

and obviously everything in between.

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 whydoidoit · Mar 01, 2014 at 09:56 AM 0
Share

Looks like he is doing a damped lerp to me - nothing wrong with that.

avatar image MadJohny · Mar 01, 2014 at 10:16 AM 0
Share

since the code runs everyframe, it should work like a damp anyway

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

22 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

Related Questions

How do I lerp the position and rotation? 1 Answer

Is it possible to use a quaternion from a gameobjects position to another gameobjects position? 1 Answer

Flip over an object (smooth transition) 3 Answers

Unfreezing rotation causes the position and rotation go crazy 0 Answers

AngryBots like character rotation system 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