prevent to move 3d object on certain direction

hello all,
as my final project, i try to make AR application that run on android platform.
i have used and try to modify this code(vuforia sdk tutorial) > https://developer.vuforia.com/resources/dev-guide/unity-drag-ar-object-screen-your-finger
and it’s successfully move my cube object. but i have some case that sometimes my object cannot be moved on y axis(upward and downward) or z axis(backward and forward).

i try to make y axis to be zero but it’s not working… i just can move my object to right and left, but not to backward and forward.

then i’ve tried to add rigidbody and checked y axis on Freeze Position but i still can move my object upward and downward

thanks for your help

If you add a ridgidbody and check freeze Position, you only prevent the objects to be moved by the physics engine. If you set the position by code or move the object in scene view it will move, because the movement is not coming from the physics engine.

To hold your object on y axis at zero you can set it´s position to zero every frame, somewhere in Update():

    void Update() {
     
      theObject.transform.position.Set(theObject.transform.position.x, 0.0f, theObject.transform.position.z);
     
    }