Hey,
So I am trying to make my object rotate naturally like any bike crank would… DataShow.data0 is the angle i am getting from my pedal. Now if I put value like 200 in there it works as intended but if I leave this data0 variable there ist doesnt rotate slowly to that angle but just jumps to it. I tryied printing values of data0 and they are from -200 to 200, and putting a value in that range insted of variable works. What am i missing?
Edit:
I am getting data0 from script that was loaded in another scene and has dontdestroyonload. So I start getting data, so I have to switch scenes to actually use my code, that got me thinking that Time.time might not be the best so i tryied Time.timeSinceLevelLoad but it did not help.
You should use Slerp, I think. (Spherical linear… something something. )
It’s format is basically the same as Lerp, which you’re not using correctly.
Lerp/Slerp are often best used in Coroutines, I find… It’s not necessary, but seems easier.
You used FixedUpdate : do you want to use physics to rotate? That would be different.
Also, I am pretty sure you should use localRotation.eulerAngles.(x/z) instead of localRotation, which also has x,y,z, and ‘w’. for the 4 parts of a Quaternion.
Don’t use Lerp with Time.time like that. The third parameter to lerp, t, is not time, it is an interpolation parameter and should be between 0 and 1.
Lerp does linear interpolation between two values a and b, when t = 0, the returned value is equal to a, when t = 1, it is equal to b, and when it is for example 0.5, the value will be halfway between a and b.
Time.time will almost always be greater than 1, and so the value will always be b.