How to move cube from first position to specific one?


I need to move cube from point “a” to point “b”. Movement should be smooth, not momentary. Also cube should face it’s direction.

Any ideas how to realise it?

Tried to use this:

Vector3 startm = new Vector3(px - 0.5f, 0.5f, py - 0.5f);
Vector3 finm = new Vector3(cx - 0.5f, 0.5f, cy - 0.5f);
Player.transform.position = Vector3.MoveTowards (startm, finm, Time.deltaTime);

But if I use this code, cube momentary moves just a little bit to its direction and stops. If I change “Time.deltaTime” to “100 * Time.deltaTime”, cube reach position, but still momentary - no smooth movement.

Thanks in advance for help!

You need to put that code into the Update() function, or a Coroutine and start it, otherwise the code wilkl only execute once (one frame).

You can first make the gameobject look at the point and then just use transform.position += …;

Vector3 pointB = new Vector3(x, y, z);
    transform.position += transform.forward * speed * Time.deltaTime;

You need to add speed variable as int/float and pointB as vector3