Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Player weapons should only hurt OTHER players. How?

Discussion in 'Multiplayer' started by jerotas, Feb 24, 2015.

  1. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    It seems like it should be easy, but I've tried a bunch of things and I can't figure out a way to make it work. Currently, we Instantiate all player weapons on the same client as the attacking player (not always on the server). We need each player's melee attack (I spawn a sphere) to not hurt the player who did the melee, but it should hurt any other players that touch it via normal trigger enter stuff. This should work with 2, 3 or 4 players.

    How do we go about making this happen?

    Currently we use Bolt (don't think that necessarily matters), but getting answers on their forum isn't the speediest thing all the time, so I'm asking here.
     
  2. adi7b9

    adi7b9

    Joined:
    Feb 22, 2015
    Posts:
    181
    why not always on the server? I think is easier to follow and to write a script for the "spawning sphere".
     
  3. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    If that makes the scenario easier, then sure...
     
  4. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Not 100% sure how it works in Bolt.

    But normally your weapon is owned by some player, and often the weapon or the owner of the weapon got a networkID attached of some kind. You can make a check and see if the trigger colliders owner networkID == the player owners networkID and then ignore it.

    If you got an authoritative setup this check should be handled on the server and not the clients in order to prevent cheating.
     
  5. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    Not sure on bolt but its more authoritative oriented, but on photon, without an authoritative setup i would just deactivate the damage trigger on all session that are not server

    like that:
    Code (CSharp):
    1. public void AttackEvent(bool check_doDamage)
    2. if(DoTheLogic)//whatever server or client you decide
    3. {
    4.   if(check_doDamage)
    5.     DoDamage()
    6. }
    7. //everyone should run here
    8. if(check_doDamage)
    9. PlayDamageSound()
    10. else
    11. PlayOtherSound()
    12. PlayAttackAnimation()
    13.  
    14.  
    you can also use that: http://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html
     
    Last edited: Feb 24, 2015
  6. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ok thanks for the ideas guys!