Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question how to deal damage properly/better using PUN 2

Discussion in 'Multiplayer' started by ShadowFlame45, Mar 18, 2023 at 8:40 PM.

  1. ShadowFlame45


    Nov 6, 2021
    for my game, i am storing health as a custom property. whenever a bullet collides with a player, it finds the player's photon view, takes the current health, then subtracts by a certain amount of damage.

    this works for most types of guns, but for guns with multi shot, like a shotgun, it won't. all of the bullets take the same original health, then all subtract by a certain amount of damage, essentially causing the damage to equal to one bullet. this problem is most likely caused by custom properties not updating with in a frame.

    is there a better way to approach dealing damage, or is there some way to force update custom properties?
  2. tobiass


    Apr 7, 2009
    I don't know if it's a common approach to have shotguns shoot individual bullets...
    One client should calculate the damage. You could collect damage for a frame, then after that is resolved, send all damage at the end of the frame.
    In doubt, have a local variable to store the health, work with that and update the custom properties accordingly, several times a second.