Player cannot move through objects, but tries too...

So my problem is this: if I continue to press forward next to a cube with my hand-crafted first person controller, he tries to pass through the cube.

This was my first try at fixing this…

 if(!Physics.Raycast(transform.position, Vector3.forward, 1))
  {
  transform.Translate(x, 0, 0);
  Debug.Log("test");
  }

 if(!Physics.Raycast(transform.position, Vector3.left, 1) && !Physics.Raycast(transform.position, Vector3.right, 1))
  {
  transform.Translate(0, 0, z);
  }

…but it didn’t work. I think I simply scripted the if statements wrong, but…

What I do is set my motion to have a speed variable that is defaulted to 1. When I run I increase this var. When my character buts against a collision I make a raycast in the direction the player is moving in. If the raycast is < threshhold then I set the player speed to 0 as long as the player is attempting the move in that direction.

This is a technique that I’ve also used in 2D games when my characters are butted up against environmental objects.