Demigiant Forum

Unity Assets => DOTween & DOTween Pro => Topic started by: SMaton on September 03, 2015, 04:35:10 PM

Title: Copy path and correct elapsed time
Post by: SMaton on September 03, 2015, 04:35:10 PM
Hello everyone,

I'm currently struggling which seemed to be a trivial problem:

I have a game object of a given type that follows a path. The path has been created using this code:

Code: [Select]
       m_currentTween = transform.DOPath(m_currentMove.path, m_speed, PathType.CatmullRom, PathMode.Full3D, 10).SetSpeedBased().SetLookAt(0.01f).SetEase(Ease.Linear).SetUpdate(UpdateType.Fixed).OnUpdate(MoveUpdate).OnComplete(MoveComplete);

Later on in the game, upon an event, I have to change the type of object BUT I have to keep the current path AND the position on the path. So we do this:

Code: [Select]

float _elapsed = m_currentTween.fullPosition;

MoveController headPiece = (MoveController)GameObject.Instantiate(m_headPrefab, nextPos, nextRot);
m_currentTween = headPiece.transform.DOPath(m_currentMove.path, m_speed, PathType.CatmullRom, PathMode.Full3D, 10).SetSpeedBased().SetLookAt(0.01f).SetEase(Ease.Linear).SetUpdate(UpdateType.Fixed).OnUpdate(MoveUpdate).OnComplete(MoveComplete);
m_currentTween.fullPosition = _elapsed;

We also tried Elapsed() and Goto()...

Thing is that the instantiated object does not appear at the exact same position as the original object. In fact, the behavior looks quite random along the path and even leads to a movement which first moves the new object to the starting point of the path.

What would be the correct procedure to actually "transfer" the current path and position on the path to a newly instantiated object?

Best regards,
Title: Re: Copy path and correct elapsed time
Post by: Daniele on September 03, 2015, 05:19:55 PM

All tweens are initialized as soon as they start playing. Before that, any call to something like fullPosition might create issues. Call ForceInit ( before setting the fullPosition and it should work.