Eonirr

Untitled

Feb 11th, 2026
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. IEnumerator MoveOverDistance(Vector3 targetPosition)
  2. {
  3. Vector3 startPos = transform.position;
  4. Vector3 direction = (targetPosition - startPos).normalized;
  5.  
  6. float distance = Vector3.Distance(startPos, targetPosition);
  7. float currentDistance = 0f;
  8.  
  9. while (currentDistance < distance)
  10. {
  11. float step = speed * Time.deltaTime;
  12.  
  13. transform.position += direction * step;
  14. currentDistance += step;
  15.  
  16. yield return null;
  17. }
  18.  
  19. transform.position = targetPosition;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment