Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator MoveOverDistance(Vector3 targetPosition)
- {
- Vector3 startPos = transform.position;
- Vector3 direction = (targetPosition - startPos).normalized;
- float distance = Vector3.Distance(startPos, targetPosition);
- float currentDistance = 0f;
- while (currentDistance < distance)
- {
- float step = speed * Time.deltaTime;
- transform.position += direction * step;
- currentDistance += step;
- yield return null;
- }
- transform.position = targetPosition;
- }
Advertisement
Add Comment
Please, Sign In to add comment