# Uniform rotation - uniform lerp

 0 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. more ▼ asked Dec 02 '11 at 01:52 PM roamcel 1.2k ● 37 ● 40 ● 44 What are you using as the third parameter in your Lerp funcion? Dec 02 '11 at 02:04 PM cj_coimbra 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 Mathf.MoveTowards right now, but haven't made progresses there either. Dec 02 '11 at 02:09 PM roamcel add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

1 answer: sort voted first
 0 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); } `````` more ▼ answered Dec 02 '11 at 03:12 PM Owen Reynolds 11.5k ● 1 ● 7 ● 45 Precious info, thanks a lot Dec 05 '11 at 07:00 AM roamcel add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Topics:

x2173
x358
x265
x3

asked: Dec 02 '11 at 01:52 PM

Seen: 1194 times

Last Updated: Dec 05 '11 at 07:00 AM