In the end it's working fine. I just wonder if I must move gameobject with rigidbody in fixedupdate with addforce or other rigidbodies or using just update is also good ?
void Update() { switch (state) { case TransitionState.MovingTowards: var v = destinationTransform.position - transform.position; if (v.magnitude < 0.001f) { state = TransitionState.Transferring; originTransform = destinationTransform; timer = 0; return; } t += Time.deltaTime; float s = t / duration; transform.position = Vector3.Lerp(originPosition, destinationTransform.position, curve.Evaluate(s)); break; case TransitionState.Transferring: timer += Time.deltaTime; this.transform.position = Vector3.Lerp(originTransform.position, destinationTransform.position, timer); if (timer >= 1.0f) { this.transform.parent = destinationTransform; transform.localPosition = new Vector3(0, 0, 0); isChild = true; state = TransitionState.None; this.enabled = false; return; } break; default: this.enabled = false; return; } }
FixedUpdatefor physics-related stuff since it is framerate-indipendent and always called before physics updates (collisions etc.) occur. This might be helpful.