Brackeys / MultiplayerFPS-Tutorial

A video series on making a multiplayer first-person shooter in Unity.
The Unlicense
654 stars 287 forks source link

RaycastHit _hit; if statement not working #23

Open IpanTheWrongWay opened 6 years ago

IpanTheWrongWay commented 6 years ago

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
    }     
}
IpanTheWrongWay commented 6 years ago

ugh....

On player prefab, the mask was set to only Weapon, instead of everything but localPlayer and Weapon.