Hello,
I have a problem that I tried to solve using various YouTube tutorials and answers from this forum and I’ve managed to narrow it down to a camera issue, but I understand now that I can’t solve it without help, so I’ve decided to ask here for assistance.
Namely, I’ve set up a Camera in an RTS fashion that suits my needs and spawned a number of spheres on the plane. Each sphere is clickable and changes color on click. I want to be able to guide an object on the same plane where spheres are by clicking on the empty space so I’ve set up a plane and detected a mouse click:
Plane plane = new Plane(Vector3.up, Vector3.zero);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (plane.Raycast(ray, out float entry))
{
// here I create an object in order to be able to determine
// the offset that is appearing, but its not offset it seems
var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
var hitPoint = ray.GetPoint(entry);
go.transform.position = hitPoint;
}
I’ve noticed that position is not correct and that coordinates are off.
However, I’ve spent some time trying to solve it and I understand now that problem is appearing most likely due to the camera position and rotation (see image) and that when I click under red sphere
it is not translating my exact click point correctly. When I deleted my RTS camera, and used Main camera that was reset to 0 it was a bit jerky (position kept shifting slightly) but an object I created appeared exactly where I clicked on screen. That game angle is not right for me, so I changed back to different rotation, and again object started instantiating again in a very narrow area to the left(see image)Can someone suggest how to overcome camera rotation when capturing mouse click?
Thanks in advance,
LD