# Moving object to point a to point b smoothly

I am working on a problem where distance between the point A and B or given and object of interest should move smoothly from A to B.

I can control only control the speed of the object using this object should start slowly from point ease in and ease out at point B and need to exactly land on point B

I tried implementing ease in speed using distance covered however, at the beginning distance covered will be zero there will be starting problem. I solved starting problem using time elapsed as reference however this will not work precisely stoping object at point B, so I used distance remaining as a key to ease out.

This works for larger distance for smaller distance yet to tweak the code . Overall implementation messy not satisfied. Is there any generic solution to solve this problem? Note speed just a parameter controls overall movement of object, I can't say there is a exact relationship speed and distance covered.

(Unity developers: Note I am trying to control the movement of the character using three animation idle:speed=0, slowwalk:average speed=1, fastwalk: average speed=2)

• I've interpolated using a sigmoid curve in the past. Would that work for you? – RobM May 12 '16 at 8:32

If I understand your question correctly, you want to smoothly move an object from point A to point B.

I would use a coroutine:

private IEnumerator Move_Routine(Transform transform, Vector3 from, Vector3 to)
{
float t = 0f;
while(t < 1f)
{
t += Time.deltaTime;
transform.position = Vector3.Lerp(from, to, Mathf.SmoothStep(0f, 1f, t));
yield return null;
}
}


And I would start it by calling:

StartCoroutine(Move_Routine(this.transform, Vector3.zero, Vector3.one));

• He wants it to ease in and our rather than linear interpolate I think – RobM May 13 '16 at 15:24
• @RobM my code is using a smooth step in there, and if that's not smooth enough you can always do this Mathf.SmoothStep(0f, 1f, Mathf.SmoothStep(0f, 1f, Mathf.SmoothStep(0f, 1f, t))); – Iggy May 13 '16 at 15:26
• Aha! SmoothStep. Wasn't aware that it performs a sigmoid type of interpolation. – RobM May 14 '16 at 18:41