Raycasting to imitate maze walls

I’m working on a project to convert a few hand-drawn mazes into digital form, with full player navigation and such. At the moment I have the maze imaged textured onto a floor piece and have the player character raycast downward to determine if it has run into a boundary. It seems to work (in a rough sense), but is incredibly “sticky” most of the time and often allows the player to slip through the walls (you can see the game in action here). Any ideas on how to smooth out the gameplay?

I’m including the wall detection code, if anyone wants to take a look.

Thanks

function WallDetection(){
	var hit : RaycastHit;
	if (Physics.Raycast(transform.position, Vector3(rigidbody.velocity.x*Time.deltaTime,-0.6,rigidbody.velocity.z*Time.deltaTime), hit)){
		var texture : Texture2D = hit.collider.renderer.material.mainTexture;
		var pixel = hit.textureCoord;
		var pixelX : int = pixel.x*texture.width;
		var pixelY : int = pixel.y*texture.height;
		var p = texture.GetPixel(pixelX,pixelY);
		var rgb : float = p.r*p.g*p.b;
		if(rgb<0.2){
			if(Physics.Raycast(transform.position, Vector3(rigidbody.velocity.x*Time.deltaTime,-0.6,0))){
				rigidbody.velocity.x *= 0;
			}
			if(Physics.Raycast(transform.position, Vector3(0,-0.6,rigidbody.velocity.z*Time.deltaTime))){
				rigidbody.velocity.z *= 0;
			}				
		}else{
		}
	}
}

I would review the docs on Physics.Raycast: Unity - Scripting API: Physics.Raycast

The second argument is supposed to be a direction.

It is a direction.

I would suggest doing some kind of pre-processing to generate a set of colliders to represent the lines, rather than casting against the lines themselves. Casting against the lines tells you if you’ve hit one, but won’t tell you things like the valid component of the motion vector. If you just use colliders and push a rigidbody around all of that is handled for you, and you’ll slide along walls etc. without having to do any real work.

Thanks for the replies.

I definitely think that converting the image to colliders would be most fluid as far as gameplay is concerned, but all attempts I’ve made at this point to manage that process have been fruitless (hence the raycasting solution). Any recommendations on how to handle the preprocessing? Everything I’ve tried so far has resulted in absurd levels of memory bloat.