Tracking to position with collisions

hey im making a game and im trying to get agameobject to go to a position. its hard to explain heres an example…

if i have a cube and i have a smaller sphere and the sphere is moving to the same position as a emply gameobject. (the sphere and cube have colliders) then i move my empty gameobject into the cube. the sphere then follows the empty gameobject inside of the cube

BUT i want the sphere to go as close to the game object as possible with out going inside of the cube

BUT (again) if the empty gameobject in in the cube and the sphere is trying to follow it but only goes to the edge of the cude. i want to be able to move the empty gameobject up and the sphere move up and then when i move the empty gameobject out of the cube the sphere starts following it again

that was hard to explain for me. you might not even get what im talking about But if you do
help would be greatly appreciated
thanks .Scott

To make the sphere stop moving inside the cube(Where the empty object is). You need to set the movement of the sphere to stop moving within a specified distance of the empty object.

What I would recommend is getting a reference to the empty game object, and utilizing it with an if statement that checks a Vector3.Distance.

For example:

//Move towards only when the target is further than maxDistance from the enemy.
if(Vector3.Distance(target.position, myTransform.position) > maxDistance) {
	// Move towards target
	myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}

For example if you set the maxDistance to 2. The sphere will only start moving once the empty gameobject is further than 2 distance away from it.