- Home /
iTween ValueTo interpolation ending with wrong value
Hello everyone.
I'm using ValueTo with a float.
My "from" value is 0 and my "to" value is 4.3 .
I used the function I'm calling from ValueTo to check what are the actual values that iTween is giving out.
The last 3 values where:
4.3
34.2
65.3
So I end up with 65.3 as the value....
Any clues as to why this is happaning?
Anyone else encouterd this bug?
I reported this issue at iTween Project
Thanks!
This is very odd. Can you provide a short self contained code that demonstrates the problem?
I'll do that on Sunday when i get back to the office.
Thanks.
I seem to have deleted that script.
But this is what I did:
I had a loop the goes over a list of gameobjects.
I check for a condition to see if I need to use iTween.ValueTo on the gameobject (only one in my case).
If the condition is true, the gameobject is given an iTween.ValueTo.
The iTween.ValueTo is given: from 0, to 4.9, time (can't recall), and all funcation calling related stuff (onupdate).
In the function that is being called, I just set a debug.log to show the value.
Thanks!
Answer by DannyB · Jun 30, 2013 at 07:49 AM
Well, without your exact iTween parameters it would be harder to offer help. But, I can tell you this: From my iTween experience, I can say ValueTo is working as expected.
There are three reasons that may give you some weird values:
The time of the tween is too short.
And/or it takes iTween a bit longer than expected to start the tween (i.e. the infamous AddComponent hiccup).
And/or you are using some more complex ease type (e.g. elastic, bounce, easeOutBack).
As you know, iTween adds a component to your object that is responsible for the tween. The first time it does that, you sometimes experience hiccups. If the tween is too short, then by the time it starts, it should already be at a higher value (nearing its end) so the update loop may be called only a few times - a couple of times with the values that are near the "from" value, and a couple of times with values near the "to".
What you can do to remedy the situation?
Check if increasing the time of the tween helps
Check if adding a slight delay to the tween helps
Call
iTween.Init( gameObject )
on yourAwake()
orStart()
If you have many objects that start executing iTween at the same time, you must Init them beforehand and even then, you may need to consider a different approach.
Finally, in your testing, eliminate any other variable, test first with a simple script, like this:
void Start() {
iTween.Init( gameObject );
iTween.ValueTo( gameObject, iTween.Hash(
"delay" , 1,
"from" , 0,
"to" , 4.9f,
"time" , 0.2f,
"onUpdate" , "UpdateValue",
"easeType" , iTween.EaseType.easeInOutBack
));
}
void UpdateValue( float val ) {
Debug.Log(val);
}
I think the problem is the time.
I'm providing very short times.
I can't really change the times.
But I guess that solves my question.
Do you think it will have the same issue if I just use $$anonymous$$athf.Lerp?
Short times may still work with iTween. But, only if you can iTween.Init()
it at least a quarter of a second or so before you need to call iTween.
With any of Unity's internal functions you are unlikely to have the same issues. iTween's biggest Achilles heal (but also its strength) is the fact that it adds a component at runtime. I believe this is the root cause for your hiccup, that in your case, manifests itself by missing critical frames.
Your answer
Follow this Question
Related Questions
Kinematic rigidbody with interpolation issue 0 Answers
How do I interpolate a value up and then back down? Gradual interpolation 2 Answers
can someone explain how using Time.deltaTime as 't' in a lerp actually works? 5 Answers
Unity Networking. Player flickers. 0 Answers
[PUN] Movement Interpolation 1 Answer