Hi, I have a three part animation, in the first one the code creates a coin and then moves it from a position to another in global coordinates:
GameObject gCoin = GameObject.Instantiate(
prefabCoinGO, starts[j].position + Vector3.up*2.5f, starts[j].rotation
) as GameObject;
Transform tCoin = gCoin.GetComponent<Transform>();
Tween twCoin = tCoin.DOMove(ends[j].position + Vector3.up*2.5f, timeToTravelCoin)
.OnComplete(() =>
{
RemoveCoin(gCoin);
})
;
the second and third part, are two more animations but in local space, if i do those with this approach:
float t = Time.time;
twCoin.OnUpdate(() =>
{
//I tried with a tCoin.Translate(...,Space.Self) too ,same result
Vector3 lPos = tCoin.localPosition;
tCoin.localPosition = Vector3.Lerp(
lPos,
lPos + Vector3.up * Mathf.Sin(
Mathf.PI * 100 * Time.deltaTime * (Time.time - t)
)*4
, Time.deltaTime*10);
tCoin.Rotate(Vector3.up * Time.deltaTime * Mathf.PI * 60);
})
;
there are some of the coins that flickers in position, jumping with bad Y coordinates, maybe because it crosses the 0,0,0 point to another axis.
But, if i do this:
tCoin.DOLocalMoveY(-0.23f, 0.6f).SetLoops(-1, LoopType.Yoyo)
.SetEase(Ease.InOutSine);
tCoin.DORotate(Vector3.up * 360f, 3f, RotateMode.FastBeyond360)
.SetLoops(-1, LoopType.Restart).SetEase(Ease.OutSine);
it works perfectly, what if i want to use OnUpdate(), does it keep a good track of the localposition or should i change dotween update for fixedupdate?