Moving an object to come closer to the camera, then back to its original position

So Ive been trying to make an object come towards my camera as im holding down the mouse button, then I want it to return back to its point…smoothly.

            var heading = mainCamera.transform.position - innerSphere.transform.position;
            innerSphere.transform.position = heading * Time.deltaTime;

I cant even get the first part to work, this just teleports the ball off instantly to some random location.

You just created heading, which is difference vector of two positions. So is just lukę creating new position, which is not what you want. What you may try to use instead, is Lerp. Search for that keyword Lerp+Vector and you wilk find tons of solution. There are albo other methods.

Ill look into the Lerp. I managed to make a sphere pull back towards my camera and then move back to its original position using Translate. All I wanted was the visual effect, no physics, so this is working fine.

For those interested here is my code but ignore the comments they are old

//holding button down increases a force variable
        if (Input.GetButton("Fire1") && !shotBall)
        {
              
            force += 0.1f;
            cinderlingRB.drag = .03f;
            //want to grab inner spheere and pull it out
            innerSphereMoving = true;
            innerSphereRetracting = false;


        }

        if (innerSphereMoving)
        {
            MoveInnerSphere();
        }
          
        void MoveInnerSphere()
        {
            Vector3 heading = mainCamera.transform.position - innerSphere.transform.position;
            //innerSphere.transform.position = heading;

            targetPosition = mainCamera.transform.position; // Get position of object B
            currentPosition = innerSphere.transform.position; // Get position of object A
            directionOfTravel = targetPosition - currentPosition;
            if (Vector3.Distance(currentPosition, targetPosition) > .1f)
            {
                innerSphere.transform.Translate(
                    (directionOfTravel.x * speed * Time.deltaTime),
                    (directionOfTravel.y * speed * Time.deltaTime),
                    (directionOfTravel.z * speed * Time.deltaTime),
                    Space.World);
            }
            innerSphereMoving = true;

        }
      

        //releasinbg button shoots
        if (Input.GetButtonUp("Fire1") && !shotBall)
        {
          
            Debug.Log("SHOULD HAVE SET DRAG TO DEFAULT");
            shotBall = true;
            Shoot();
            force = 0;

            innerSphereMoving = false;
            innerSphereRetracting = true;

           // innerSphere.transform.position = bigSphere.transform.position;



        }

        if (innerSphereRetracting)
        {
            RetractInnerSphere();

        }

        void RetractInnerSphere()
        {
            targetPosition = bigSphere.transform.position; // Get position of object B
            currentPosition = innerSphere.transform.position; // Get position of object A
            directionOfTravel = targetPosition - currentPosition;
            if (Vector3.Distance(currentPosition, targetPosition) > 0f)
            {
                innerSphere.transform.Translate(
                    (directionOfTravel.x * 100 * Time.deltaTime),
                    (directionOfTravel.y * 100 * Time.deltaTime),
                    (directionOfTravel.z * 100 * Time.deltaTime),
                    Space.World);
            }
            innerSphereRetracting = true;
        }