Why does my MovePosition never really bring me to my target location

I want my object to move to a certain location called spawningPoint.

    	void Start () {
    		rBody = GetComponent<Rigidbody2D> ();
    		anim = GetComponent<Animator> ();
    		spawningPoint = transform.position;
    		//Debug.Log ("My spawning point is (" + spawningPoint.x + "), (" + spawningPoint.y + ")");
    	}
    	
    	// Update is called once per frame
    	void FixedUpdate () {
    
    		if (anim.GetBool("isInRange") == false){
    			Vector2 targetLocation = new Vector3 (spawningPoint.x, spawningPoint.y, 0);
    
    			anim.SetFloat ("x", targetVector.x);
    			anim.SetFloat ("y", targetVector.y);
    
    			targetVector.x = targetLocation.x - transform.position.x;
    			targetVector.y = targetLocation.y - transform.position.y;
    
    			distance = Vector3.Distance (rBody.transform.position, spawningPoint);
    
    			if (distance > 0.5f) {
    				Debug.Log ("Moving to spawning point. Distance to spawning point is (" + distance + ")");
    				// This move the object to the target's location but I never really reach it as distance never reaches 0
    				rBody.MovePosition (rBody.position + targetVector * Time.deltaTime * returnSpeed);
    			} else {
    				transform.position = spawningPoint;
    				Debug.Log ("I'm at spawning point. Distance to spawning point is (" + distance + ")");
    				anim.SetBool("isMoving", false);
    			}
    		}
    	}

I notice on the console that the distance just keeps getting smaller and smaller but never really reaches 0 so I just had it “teleport” to the location when I get “really close”.

I feel like I’m cheating here. Is there a better way to do this (not using transform.position)?

I’m not quite sure, but MovePosition does some smoothing, and you are also multiplying by Time.deltaTime.

Try removing Time.deltaTime.

It looks like its moving by a percentage of the distance between the two objects. Which is basically infinite, so it will never actually reach the target, or it will take a long time.


EDIT: From docs RigidBody.MovePosition “If Rigidbody interpolation is enabled on the Rigidbody, calling Rigidbody.MovePosition results in a smooth transition between the two positions in any intermediate frames rendered”.