dotween
dotween copied to clipboard
How to make OnUpdate and ChangeEndValue work properly?
I want to make object 1 to follow object 2, within a fixed time(when object 2 moves to opposite direction, it should makes object 1 to move faster in order to keep the whole move time fixed).
Problem 1: The following codes do not work at all. obj1 doesn't move at all. Not sure if it's a bug.
var tweener = obj1.transform.DOMove(obj2.transform.position, 5f);
tweener.OnUpdate(() => {
tweener.ChangeEndValue(obj2.transform.position);
});
Problem 2: Using the following codes, obj1 moves and follows obj2. However its speed reduces gradually and never reaches obj2. I think the ChangeValues call must have reset the duration to 5 somehow.
var tweener = obj1.transform.DOMove(obj2.transform.position, 5f);
tweener.OnUpdate(() => {
tweener.ChangeValues(obj1.transform.position, obj2.transform.position);
});
If I know how to get the remaining duration time of a tweener, and maybe this following codes may work properly. But I haven't found a way to get te remaining duration in documentation.
var tweener = obj1.transform.DOMove(obj2.transform.position, 5f);
tweener.OnUpdate(() => {
tweener.ChangeEndValue(obj2.transform.position);
tweener.ChangeValues(obj1.transform.position, obj2.transform.position, newDuration: tweener.currentRemainingDuration);
});
Any help is appreciated, thanks!