# How to slerp two objects

**URL:** https://discussions.unity.com/t/how-to-slerp-two-objects/70021
**Category:** Questions & Answers
**Created:** [May 3, 2013, 5:43am UTC](https://discussions.unity.com/t/how-to-slerp-two-objects/70021 "2013-05-03T05:43:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Hello\_Lp](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Hello\_Lp](https://discussions.unity.com/u/Hello_Lp)
#### Post date: [May 3, 2013, 5:43am UTC](https://discussions.unity.com/t/how-to-slerp-two-objects/70021/1 "2013-05-03T05:43:40Z")

</div>

I am trying to swap two objects: origin and target. The colliders are taken from hitInfo when I raycast. I can’t seem to figure it out properly even after following the posts on the forum.

When I change the `translationTime = 30f`, the Debug.Log at the bottom still instantly shows that the position are changed, even though there is no different on the game preview scene (i.e. the object did not move).

This is not called within the Update(). How do you use slerp to move an object?

```
   public void animSwapTile(Collider origin, Collider target){
		float translationTime = 30f;
		float timer = 0f;
		Vector3 posA = origin.transform.localPosition;
		Vector3 posB = target.transform.localPosition;
		
		while(timer < translationTime){
			Vector3 center = posA + posB * 0.5f;
			center -= new Vector3(0f, 1f, 0f);
			Vector3 partA = posA - center;
			Vector3 partB = posB - center;
		
			posA = Vector3.Slerp(partA, partB, timer/translationTime);
			timer += Time.deltaTime;	
		}
		
		if(timer >= translationTime){
			posA = posB;	
			Debug.Log(posA + ", " + posB);
		}
	}

```

---

<div class="post-metadata">

### Author: ![DaveA](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@DaveA](https://discussions.unity.com/u/DaveA)
#### Post date: [May 3, 2013, 6:22am UTC](https://discussions.unity.com/t/how-to-slerp-two-objects/70021/2 "2013-05-03T06:22:25Z")

</div>

Ugh. Why is this not in Update? That while loop is going to fail you unless there is a yield of some sort in there. Just use Update. Or FixedUpdate.
