I’m getting curiously close but slightly off X,Y coordinates back when trying to aim with the Mouse. Here is a visual example of the issue (and code I’m using below that). Each sphere is .25 X units away and I drew a red dot where the cursor is. The position I get back, circled on the right of the pic, is for 4.25 which should be the center of the sphere, not slightly to the left of the sphere.
The position in X gets off by about .1 the further across the screen I go from 0. It makes the aim just slightly off and is kind of frustrating. Here’s the pic:
You can also see the aim get just slightly off here on my webplayer, the effect is worse furthest to the left/right or the bottom left/right: https://dl.dropboxusercontent.com/u/30841964/Photos/Firefly.html
It’s minor, but it’s definitely reading me the wrong position X,Y coordinates the further away from 0 I get. Here’s code:
function GetXY()
{
var ray : Ray;
var dist : float;
plane = new Plane(cannonCamera.transform.position, Vector3.up);
ray = cannonCamera.ScreenPointToRay(Input.mousePosition); // create a ray from the mousePosition
if (plane.Raycast(ray, dist)) //dist is a float from the ray start to the hit point
{
target = ray.GetPoint(dist); //target is a Vector3 describing where the mouse is hovering
target.z = -4; //this gets set to avoid any z value (the cannon sits at z of -4)
}
}
Any idea why? Any suggestions? Thanks in advance for any help.