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{
}
}
}