I have a problem with raycasting. It has a offset of a half a tile every time i raycast.
So either i round the value wrong or i raycast wrong. Because this dont work at all.
Above is a visualisation of the problem that i am now going to try to explain.
The red tile gets activated when i raycast at the position of the red circle.
Same goes for the orange circle and tile. But the blue tile does not get activated when i click on the first half it (about the same position as the blue circle)
Above this text is how it looks ingame and how the camera is angled. Dont know if that could be the problem behind false values.
Here is also snippets of code on how i raycast and take out the value of the tile in question
void Update()
{
if (myTurn)
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit))
{
float tempX = hit.point.x / 10.0f;
float tempZ = hit.point.z / 10.0f;
ActOnTap((int)tempX,(int)tempZ);
}
}
}
} //End of Update
The tiles are placed in the following way
Tile1: 0, 0, 0
Tile2: 10, 0, 10
Tile3: 20, 0, 20