I am trying to move four objects and a SteamVR player by updating the transform.position. This works fine, however it does not look so well because the movement is like instant. That is why I want to use Vector3.MoveTowards().
Somehow, the code below is not doing the job. I was hoping that someone could help me out.
private void ZoomObject(Vector3 currentPlayerPosition, float height, float distance)
{
TPNorthObject.transform.position = Vector3.MoveTowards(TPNorthObject.transform.position, new Vector3(0, height, distance), 10 * Time.deltaTime);
TPEastObject.transform.position = Vector3.MoveTowards(TPEastObject.transform.position, new Vector3(distance, height, 0), 10 * Time.deltaTime);
TPSouthObject.transform.position = Vector3.MoveTowards(TPSouthObject.transform.position, new Vector3(0, height, -distance), 10 * Time.deltaTime);
TPWestObject.transform.position = Vector3.MoveTowards(TPWestObject.transform.position, new Vector3(-distance, height, 0), 10 * Time.deltaTime);
}
What I expected was, that the object would float to the new vector place. However it does not seem to do that.
Can someone give me some insight or advice?
Thanks in advance
From Unity's documentation:
https://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html
That is to say that MoveTowards doesn't do the smooth animation for you. If you wan't some kind of animation effect, your ZoomObject function needs to be called in a loop until your object reaches the target position. Check out the example on the documentation page.
You can use a loop or a coroutine to do that. Maybe something that would look like this.