Restricting Movement To One Axis (Found solutions, but they didn't work)

I’d like to completely restrict movement on a specific axis since I am making a 2d game. After searching around it seemed that the two common fixes to this problem are:

  1. Use the rigid body constraints.
  2. Use the update function to change the axis position to zero.

Neither of these solutions worked for me, and i’m at a complete loss as to where I should even be investigating. Any ideas?

Thanks,
Mark

Ok,

First be sure that your box colliders have a Z scale = 1
(since you are using planes, still you must give a scale)

Then set both objects Z Position equal values.

Then finally on rigidbody, click on Freeze Position Z check to disable movement on Z.

PS: I assume that your camera is directed to Z-Axis.

Well I wandered off and decided to work on my characters control while waiting for a response, and while doing that the problem somehow disappeared. Unfortunately I have no idea which one of my changes helped. The directions you gave is what I did initially. After that didn’t work I attempted to use the update function to change it’s position to zero every frame. So yea, i’ll just hope that it doesn’t reappear.

Thank you for such a clear response, and sorry that I forgot to mark the question.