OnCollisionEnter on server only?

Right now I have an OnCollisionEnter function on many entities which all start with

if (!BoltNetwork.isServer) return;

Is there a way to only have the function on the server? Am I wasting my time trying to optimize something that is not actually expensive? (I might have this on up to 50 entities at a time)

Comments

  • That's the way to do it. Bolt Physics are also server only and have lag compensation if you want to use them.
  • what you are doing is correct.
    you can also do

    private void Awake()
    {
    if(BoltNetwork.isClient) { Destroy(this); }
    }

    to remove a script that you only want running on the server
  • @dmg: Exactly what I need. Thanks

    @stanchion: Is Bolt Physics something special or is it just running all physics on the server? And by lag compensation do you mean interpolation/extrapolation?

    Sidenote: A little googling told me that running OnCollisionEnter is only expensive if you add the Collision object parameter, since Unity then has to create and calculate its values.
  • Interpolation/extrapolation is client side prediction, Bolt physics is different. When you shoot other players in the tutorial it uses Bolt physics
  • @stanchion: From what I can see in the advanced tutorial (part 5 - authoritative lag compensated shooting) nothing special is going on physics-wise. In the DisplayEffects function a normal Unity raycast is used. It even seems DisplayEffects is running locally. Am I missing something? :)
  • chr
    chr
    edited October 2015
    @stanchion I found BoltNetwork.RaycastAll and BoltPhysicsHit hidden in the API. Can't find it elsewhere. Do you know how the lag compensation works?

    Edit: nvm, it's in the sample project when downloading a newer version of Bolt
  • Yup, Keep in mind you will need to estimate the playercamera distance and everything to accurately create a raycast on the server.
  • @dmg Can you elaborate? Is it explained in the sample? (I haven't checked it out yet)

    Another question: What exactly is the difference between bolt and unity raycast?
  • Bolt raycast is lag compensated which means if a shot is fired 0.1 seconds ago and would've hit if the player was where he was 0.1 seconds ago, then it hits the player

    https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking
  • @stanchion That makes sense. Thanks!