C# trying to move a object

Hello, Im trying to move an object to a certain posistion as I have here

objectToMove.transform.position = new Vector3(-75, 6, -13);

And I encounterd a problem, the object moves instantly to that position as I want it to move slowly to that position (Like a space door thats sliding to the side)

I’m using a GUI button to move the door incase that matters.

Thanks in advance.

If you have a specific point that you want your player to move to, Vector3.MoveTowards is ideal. Use it like this:

float speed = 10 * Time.deltaTime;

objectToMove.transform.position = Vector3.MoveTowards(objectToMove.transform.position, targetPosition, speed); 

Note that Vector3.MoveTowards returns a Vector3 that is ‘speed’ closer to the targetPosition. This means that you can check its value and only change the position of the Transform if it is not equal to. For further reference, see the Unity docs:

You have to use Vector3.Slerp or Vector3.Lerp.

Not sure how to apply it.

Vector3.Slerp

Vector3.Lerp