Hi - I’m raycasting a cursor on the surface of a plane by placing a prefab at the ray hit point. All works as expected except that the prefab moves toward the camera (I’m raycasting from the camera view). It’s supposed to simply skim along the surface of the plane wherever the camera looks. How can I fix this?
Ray ray;
RaycastHit hit;
void Start()
{
ray = camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
}
void FixedUpdate()
{
if (Physics.Raycast(ray, out hit))
{
if (_cursor.activeSelf == false)
_cursor.SetActive(true);
_cursor.transform.position = hit.point;
print("The hit.point is: " + hit.point);
_cursor.transform.rotation = hit.transform.rotation;
print("I'm looking at " + hit.transform.name);
}
else
{
print("I'm looking at nothing!");
_cursor.SetActive(false);
}
}