When I use rigidbody.Moveposition, the object doesn't move accurately.

I’ve been using rigidbody.Moveposition for one of the objects in my game. It moves up for a set number of seconds, then moves back down for the same number of seconds, at the same speed. However, the object doesn’t always move correctly. Sometimes it’ll move higher than it should, but then move the right distance down, or vice versa. How can I make the movement more exact? This is the snippet of code I’m using to make it move:

    if(spinDirection == "up")
    
    {
    
    	rigidbody.MovePosition(rigidbody.position + Vector3(0,30,0) * Time.deltaTime);
    
        }
    
    else if(spinDirection == "down")
    
    {
	rigidbody.MovePosition(rigidbody.position + Vector3(0,-30,0) * Time.deltaTime);

}

Use in FixedUpdate() not in Update(), and change “Time.deltaTime” to “Time.fixedDeltaTime”.