MultiplayerFPS-Tutorial
MultiplayerFPS-Tutorial copied to clipboard
RaycastHit _hit; if statement not working
Sometime between episode 12 and 13, my Raycast stopped detecting hits. Any idea what is happening?
Below is the Shoot(); I added debug.logs to find the error.
[Client] void Shoot() { if (!isLocalPlayer) { return; }
//WE ARE SHOOTING, CALL THE ONSHOOT METHOD ON THE SERVER
CmdOnShoot();
RaycastHit _hit;
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, currentWeapon.range, mask))
{
Debug.Log("RaycastHit"); //DID NOT PLAY
if (_hit.collider.tag == PLAYER_TAG)
{
CmdPlayerShot(_hit.collider.name, currentWeapon.damage);
}
//we hit something call the on hit method ont the server
Debug.Log("raycasthit"); //DID NOT PLAY
CmdOnHit(_hit.point, _hit.normal);
}
else
{
Debug.Log("nohit"); //DID PLAY
}
}
ugh....
On player prefab, the mask was set to only Weapon, instead of everything but localPlayer and Weapon.