Cast ray to end of a second ray
Hello,
I have a ray extending out from the center of my camera viewport 20 units (yellow line).
I also want a ray to extend from an empty gameobject on the front of my cylinder character to the end of the yellow camera ray, which represents the center of the screen.
I have tried to set the origin of the blue ray to the transform.position of the empty gameobject on the front of my character, and the direction to a POINT at the END of the yellow ray via the following two methods:
if (Input.GetKey (KeyCode.Mouse0)) {
Ray crosshairPoint = viewCamera.ViewportPointToRay (new Vector3(0.5f, 0.5f, 0.0f));
Vector3 crosshairEnd = (crosshairPoint.origin + crosshairPoint.direction * 20);
Debug.Log ("End point =" + crosshairEnd);
Debug.DrawRay (crosshairPoint.origin, crosshairPoint.direction * 20, Color.yellow, Time.deltaTime, false);
Debug.DrawRay (_charFace.position, crosshairEnd, Color.blue, Time.deltaTime, false);
}
And I have also used the crosshairPoint.GetPoint(20) function to retrieve the end of my ray, but the blue ray seems to extend in a direction that isn't near the yellow ray at all (image).
Any ideas on how to fix this? Thank you!
Update
If I draw a ray from the map's origin (Vector3.zero), it intersects just fine, but the blue ray starting from the character's face is still offset.