Custom camera matrix messing up ScreenPointToRay? (bug?)

I’m using a custom camera projection matrix to create a shifting effect, rather than rotation (it won’t show up much in my sample, but it’s part of my gameplay).

The problem is that ScreenPointToRay doesn’t seem to take into account the changes I’m making to the matrix (at least partially). I think my changes to (0,3) and (1,3) in the camera matrix are throwing it off? I’m not sure if there’s some type of coordinate conversion I need to do to fix it up, but I’ve tried everything and I can’t get it to work correctly. As you’ll see in the sample, it works in the center, but it doesn’t shift correctly, so you’ll see that the center point is in the right spot, but to shoot the other spheres, you need to shoot much closer towards the center.

Here’s a stripped down version for download showing the problem. Use the mouse to move the cursor, and use left click or left ctrl to shoot and delete the object. The darker sphere is the center. (It’s also currently hardcoded to 4:3 aspect ratio)

www.blobvandam.com/scrap.zip

Here’s the code I have attached to my camera object-

#pragma strict
var crosshair : Texture2D;

private var camx : float = 0;
private var camy : float = 0;
private var camz : float = 0;

function Update() {


	var cam = camera;
	camx = (Input.mousePosition.x - (Screen.width / 2));
	camy = (Input.mousePosition.y - (Screen.height / 2));
	camz = cam.transform.position.z;
	var m = PerspectiveOffCenter(camx, camy, camz); 
//updates camera projection
	cam.projectionMatrix = m;
	
//detects shot
if (Input.GetButtonDown("Fire1")) {
	var shothit : RaycastHit;
	var tempray = camera.ScreenPointToRay (Vector3(Screen.width / 2, Screen.height / 2,0));
	Debug.DrawRay (tempray.origin, tempray.direction * 10, Color.yellow);
	if (Physics.Raycast(tempray, shothit, 1000)){
			Destroy(shothit.collider.gameObject);
				
	}
}


}

//alters the camera projection matrix
static function PerspectiveOffCenter(camx : float, camy : float, camz : float) : Matrix4x4 {        
var near : float = 10.0;
var far : float = 200.0;
var fov : float = 5.0;
var focalpoint = -camz;

var aa : float = (1.0 / Mathf.Tan((Mathf.Deg2Rad * fov) / 2)) / 1.33;
var ab : float = 0;
var ac : float = camx / focalpoint;
var ad : float = camx;

var ba : float = 0;
var bb : float = 1.0 / Mathf.Tan((Mathf.Deg2Rad * fov) / 2);
var bc : float = camy / focalpoint;
var bd : float = camy;

var ca : float = 0;
var cb : float = 0;
var cc : float = -((far + near) / (far - near));
var cd : float = -((2.0 * far * near) / (far - near));

var da : float = 0;
var db : float = 0;
var dc : float = -1.0;
var dd : float = 0;

var temp = Mathf.Sin(Time.time);
var m : Matrix4x4;
m[0,0] = aa;	m[0,1] = ab;	m[0,2] = ac;	m[0,3] = ad;
m[1,0] = ba;	m[1,1] = bb;	m[1,2] = bc;	m[1,3] = bd;
m[2,0] = ca;	m[2,1] = cb;	m[2,2] = cc;	m[2,3] = cd;
m[3,0] = da;	m[3,1] = db;	m[3,2] = dc;	m[3,3] = dd;
	
return m;

}





function OnGUI() {

var rec = Rect( (Screen.width / 2) - 64, (Screen.height / 2) - 64, 128, 128);
GUI.DrawTexture( rec, crosshair, ScaleMode.ScaleAndCrop, true );	

}

Has anyone got any ideas on this? I’m thinking this is possibly a bug, but as I’m new to Unity, I’m hesitant to assume it’s a bug and report it without having someone more experienced confirm it.

Did you ever find a fix for this? I suspect I’m going to have to re-create the projection matrix I’m loading manually through the camera settings to screenpointtoray works.