Hello, I am trying to add spotting similar to battlefield 3 and 4. All the players have a box collider around them that is on the layer “tagging.” I have the player send out a raycast whenever they press ‘E’ and a layermask on the ray so that it only collides with the tagging layer. It works fine when I am relatively close to the player. However, when I get more than 10-50 units away from him, it doesnt detect the collision at all. Also, the raycast maxDistance is over 600 so that shouldnt be the problem.
Code:
void RpcSendRay(){
RaycastHit shot;
Debug.Log (transform.name + " sent ray"); //this is always logged
if(Physics.Raycast (raycastItem.position, raycastItem.forward, out shot, 600f, mask.value)){
Debug.Log (shot.transform.name + " ray hit"); //I never get to this point unless really close
Debug.Log (shot.distance);
PlayerTagging pt = shot.transform.GetComponent<PlayerTagging> ();
if (pt != null) { //this if statement just makes sure they have the script and then tags them
if (pt.GetComponent<Player> ().isLocalPlayer) {
return;
}
Debug.Log (shot.transform.name + " getting tagged");
pt.tagMe ();
}
}
}