Move from one position to another in x seconds

This should be simple, I know, but for some reason, I can’t seem to wrap my mind around it…

I want to move an object from one position to another in X number of seconds. I can’t figure out how to make it work correctly.

I would like to use Vector3.MoveTowards(), but will take any solution.

I tried taking a mathematic approach, but I haven’t touched much math since high school, so be nice.

The way I’ve always used MoveTowards() is with the last argument essentially equating to the speed at which the transition should happen. I’m not sure if this is correct or not, as the last argument listed as “Max Distance Delta” doesn’t seem all that intuitive.

Anyway… I figured I needed to calculate the speed for my final argument, so I deduced:

distance = d

speed = s

time = t

d = s * t


s = d / t

I calculate the distance that needs to be traveled by subtracting my two distances (although they’re vector3s only the y value is different), let’s call this value posDiff.

Then, I attempt my transition as follows:

transform.position = Vector3.MoveTowards(transform.position, newPosition, Time.DeltaTime * (posDiff / transitionDuration))

I use an intermediate value for the transform, then assign that value to my gameobject’s transform in my actual code, but for demonstration purposes, I think the above suffices.

Any help would be awesome.

if you create a timer and figure the percentage of the timer that has passed. you can use that number to multiply to the difference of the two points.

here is the most basic math for this in case anyone is not understanding:

	public float seconds = 10;
	public float timer;
	public Vector3 Point;
	public Vector3 Difference;
	public Vector3 start;
	public float percent ;
	void Start(){
		start = transform.position;
		Point = new Vector3 (5, 5, 5);
        Difference = Point-start;

	void Update(){

		if (timer <= seconds) {
			// basic timer
			timer += Time.deltaTime;
            // percent is a 0-1 float showing the percentage of time that has passed on our timer!
			 percent = timer / seconds;
            // multiply the percentage to the difference of our two positions
			// and add to the start
			transform.position = start + Difference * percent;