Okay so I have a script attached to a player. I want them to rotate toward the crosshair position wherever it goes on screen. Thus far I have seen a lot of people do this with a raycast. But this only works if there is a hit. How do I determine the rotation if there is no hit, using a default distance of 1000.0f;
RaycastHit hit;
RectTransform crosshair = aimTarget.GetComponent<RectTransform>();
Ray ray = Camera.main.ScreenPointToRay(crosshair.position);
Vector3 direction = Vector3.forward;
if (Physics.Raycast(ray, out hit, 1000.0f))
{
Debug.Log("yes");
direction = hit.point - transform.position;
}
else
{
Debug.Log("no");
// direction = ?
}
transform.rotation = Quaternion.LookRotation(direction);
Debug.DrawRay(transform.position, direction, Color.green);