Hi,
I’m using this piece of code to cast a ray though the center of the screen
(including Debug code if I fucked it up somehow)
var hit : RaycastHit;
var ray = playerCamera.ViewportPointToRay(Vector3(0.5, 0.5, 0));
if (Physics.Raycast(ray, hit)) {
print(ray.origin);
Debug.DrawRay(ray.origin, ray.direction * 100, Color.red, 5.0);
Debug.Break();
The resulting rays origin seems to be off but direction is correct which results in ray hitting the stuff to the sides and/or below/above what it was actually supposed to hit.
I have absolutely no idea what I’m doing wrong here.
Thanks in advance.
Update: I just found found out that the more my camera is tilted, the more ‘off’ the origin of the ray is.
My camera is a child of a complex character armature and I am modifying the camera’s transform directly.
Could any of those things be affecting ViewportPointToRay?