Move a cube around a center point

Hi,

As

you can see from the picture, i want to use a sphere to push move the cube and the original position of cube is the center. When i move sphere close to the center , the cube will move relatively until the sphere pass the center. And the cube will move to the reverse position. How can i detect if the sphere pass the center or not? Any thought on that?

I’m still fuzzy on the details but let me take a shot. I assuming there are multiple cubes (one for each level), and that they move on the X axis, but not the Y or Z axis. When the finger slides into a new level you have a trigger that identifies the cube at that level. At that point you give the cube the transform of the sphere (set a public variable) and call a script method on the cube to start maintaining the distance. Based on position, you decide if the cube is to be to the left or right of the sphere. Assuming the sphere always starts in the center, the side the finger lands on will determine which way the cube moves. At each frame you do a calculation something like:

public class CubeMover : MonoBehaviour
{
        public bool bLeft = true;
        public Transform transSphere;
        
        float fSepDist = 3.0f;  
        float fMaxMovePerFrame = 0.1f;
        
        void Update ()
        {
                float fPos;
                        
                if (bLeft)
                        fPos = transSphere.position.x - fSepDist;  
                else
                        fPos = transSphere.position.x + fSepDist;  
                        
                // This will cause the block to slide rather than immediately move
                fPos = Mathf.MoveTowards (transform.position.x, fPos, fMaxMovePerFrame);  
                
                Vector3 v3NewPos = transform.position;
                v3NewPos.x = fPos;
                transform.position = v3NewPos;
        }
}

You will need to disable the movement when the sphere is in a different level.