I am trying to make it so that, if a player clicks a valid place on the game-world, a selected character will move there. So I am raycasting and grabbing the location where it hits as a target destination.
However, I have had problems with the raycast hitting other things like scenery, and other characters, rather than ignoring them until the ray hits the ground (which is the location that I want).
I tried this:
float range = 50;
Ray raycast = camerad.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(raycast, out hit, 8)) {
if(Input.GetMouseButtonDown(0)) {
selectedPosition.transform.position = hit.point;
}
}
… and then put the map tiles into Layer: User Layer 8 - “Walkable”
However, now all clicks are ignored. What am I doing wrong? Thanks!