Search Unity

How to make Raycast ignore dead players?

Discussion in 'Scripting' started by Jeepster, Jun 9, 2020.

  1. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    Hi,

    So in my multiplayer game, if a player dies, their mesh and capsule collider is turned off until they respawn.

    If a player kills another player but keeps shooting where the killed player stood, the raycast still hits the dead player even though there is no active capsule collider. I think it's because of the rigidbody, but how can I either temporarily turn off the rigidbody (if that's the issue) or make it so that my raycast temporarily can't hit the dead player?
     
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Hi,

    How about putting the players in another layer when they are dead?
    And use a layer mask to only hit the one you want with the ray.
     
    Jeepster likes this.
  3. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    I like that. I think that would work. Thanks :)