Three Dimensional Problem

I’ve made many 3D things (Newest One) based on Sen’s tutorials, and I’ve always run into the same problem. Whenever an object gets too close to the camera, it gets all messed up. Here’s the codes I use for 3D:


/*This function converts a 3 dimensional point into a 2 dimensional point on the stage
*/
function TwoToThree(Point){
 var cx = camera.x + (Math.sin(camera.rotation) * 150);
 var cy = camera.y;
 var cz = camera.z + (Math.cos(camera.rotation) * 150);
 var x = Point.x - cx;
 var y = Point.y - cy;
 var z = Point.z - cz;
 var tx, ty, tz;
 var angle = camera.rotation;
 tx = Math.cos(angle)*x - Math.sin(angle)*z;
 tz = Math.sin(angle)*x + Math.cos(angle)*z;
 x = tx;
 z = tz;
 var scaleRatio = FL/(FL + z);
 x = x * scaleRatio;
 y = y * scaleRatio;
 Point2 = new Object();
 Point2.x = x;
 Point2.y = y;
 Point2.z = z;
 Point2.tr = FL + z;
 return Point2;
}
/*This is the function that the walls in the racing game run threw for updating
*/
function WallOnEnter(){
 if(_root._currentframe != GameFrame){
  Destroy(this);
 }
 var p = new Array();
 for(i=0;i<this.points.length;i++){
  p* = TwoToThree(this.points*);
 }
 var a = 0;
 for(i=0;i<this.points.length;i++){
  if(p*.tr < 300){
   a ++;
   break;
  }
 }
 this.clear();
 if(a == 0){
  this.beginFill(this.col, 100);
  this.lineStyle(0, 0xDE0101, 25);
  this.moveTo(p[0].x, p[0].y);
  for(i=1;i<p.length;i++){
   this.lineTo(p*.x, p*.y);
  }
  this.lineTo(p[0].x, p[0].y);
  this.endFill();
 }
 var tz = 0;
 i=0;
 while(i<this.points.length){
  tz += p*.z;
  i++;
 }
 tz = tz/i;
 this.swapDepths(-tz);
}

The focal length (FL) is 300.
I image that I’d have to change something in one of these two, which is why I picked them. If anyone has ideas, I’ll be glad to try them.