|
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.
(comments are locked)
|
|
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):
Using your current value as an input 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: Lerp method: Precious info, thanks a lot
Dec 05 '11 at 07:00 AM
roamcel
(comments are locked)
|

What are you using as the third parameter in your Lerp funcion?
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.