Collision error for the x axis

Ok so im making a 2D/3D platforming game, Im just working through concepts right now and the top and bottom of my level have correct collision however i can just phase through walls of the x axis. Any edge of a block on the x axis is walk throughable. Ive never seen this happen. Can someone help please?

edit (moved from comment)

I am using Translate

if (Input.GetKey("d")) {
    transform.Translate(-Vector3.left * speed * Time.deltaTime);
if (Input.GetKey("a")) {
    transform.Translate(-Vector3.right * speed * Time.deltaTime); 

Well if you use a `CharacterController` use the `Move` method of this one. If you don't use the CharacterController you need at least a kinematic Rigidbody at your object or there will be no collision detection at all.


To restrict movement of a rigidbody to x and y (clamp z to 0) just correct the position every frame. You can do multiple movements in one frame so this can be seperated from the actual movement:

rigidbody.MovePosition(new Vector3(0,0,-transform.position.z));

This will move the object back to z == 0 whenever it would move in z direction.