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 roamcel · Dec 02, 2011 at 01:52 PM · rotationlerpspeeduniform

Uniform rotation - uniform lerp

Hi,

I am pretty familiar with the lerp function and its variants by know, but am now in need of creating a specific kind of rotation, with equal/ constant angular speed throughout the whole transition.

Basically, I need to rotate a transform from a to b with uniform speed, or with acceleration control, alternatively. The lerp function instead 'accelerates' and 'decelerates' when it nears the 'to' value, which does not fit my purpose.

Despite my numerous attempts, I was unable to come up with a solution.

What should I look for to achieve this? Is it possible to create a constant angular speed rotation with Unity's builtin functions, or do we need a special formula? Alternatively, what'd be the way to dynamically alter the T parameter in lerp to at least 'simulate' uniform speed?

I'm grateful for any advice. This problem is driving me mad.

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 cj_coimbra · Dec 02, 2011 at 02:04 PM 0
Share

What are you using as the third parameter in your Lerp funcion?

avatar image roamcel · Dec 02, 2011 at 02:09 PM 0
Share

I am not actually using lerp, since it hasn't allowed me to achieve the desired result. I however think the third parameter should vary over time in some manner. I'm looking into $$anonymous$$athf.$$anonymous$$oveTowards right now, but haven't made progresses there either.

1 Reply

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

Answer by Owen-Reynolds · Dec 02, 2011 at 03:12 PM

It helps to know that Lerp and moveTowards are only a line or two of code each. They aren't doing anything special. The angle versions only have an extra line or two checking for wrap-around (ex: 350 degs is only 20 away from 10 degs):

A=Lerp(B, C, 0.1): A = B +(C-B)*0.1 // A is 10% of the way from B to C

A=moveTowards(A, B, amt): A=A+amt; if(A>B) A=B; // add amt to A, but not more than B

Using your current value as an input a=Lerp(a, b, 0.1); allows you to call it repeatedly, moving you 10% closer each time. That's a cute trick. It's pretty much the same thing as saying speed=speed*0.9; to create friction, which affects you more when you are going faster. Of course, instead of Lerp, you could just write: a=a+(b-a)*0.1;

The two ways of moving at a constant speed are 1) adding a constant value to your angle, using RotateTowards, 2) Fixing start and stop, and changing the percent from 0% to 100%, using Lerp. The adding method is easier, but can get math errors (0.1+0.1... ten times is ten tiny rounding errors away from one.) You'll get there, but maybe a frame more or less than you really should.

MoveTowards method:

   // do this anytime to start it:
   target = whatever

   // each frame:
   angle = Quaternion.RotateTowards(angle, target, speed*Time.fixedDeltaTime);

Lerp method:

 // do this anytime to start it:
 float pct=0;
 Vector3 start=transform.rotation; // save start angle
 Vector3 end = whatever

 // each frame:
 pct=pct + speed*Time.fixedDeltaTime;
 if(pct>=1) pct=1;
 else { transform.rotation = Quaternion.Slerp(start, end, pct); }
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 roamcel · Dec 05, 2011 at 07:00 AM 0
Share

Precious info, thanks a lot

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Moving needle from one angle to another angle one time 1 Answer

Rotation used as movement 4 Answers

Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers

Clamped Turret Doesn't Want to Lerp the Other Way 2 Answers

interpolate a move variable 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