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

Rigidbody addForce on other Player

Discussion in 'Multiplayer' started by Daegit, Oct 3, 2017.

  1. Daegit

    Daegit

    Joined:
    Nov 20, 2015
    Posts:
    32
    Hallo,
    I'm looking for a workflow/Solution, to rigidbody.AddForce to other Players-GameObject-Rigidbody. Basically I do a SphereCast to get all near Colliders->Rigidbody, then calculate the direction and Rigidbody.AddForce to other Players-Rigidbody, but this way dont work on a Network.

    I'm looking for a work around or somthing that could help.

    Im using Photon Network.
     
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    If the force is an instant impulse then send either
    1: Only apply force on server and all clients will automatically update their position/velocity next send
    2: Send a vec3 to the client(s) with the force direction & magnitude.

    If the force continuous then it becomes much more complicated. Either...
    1: Calculate it client side
    2: Periodically update the vec3's direction and magnitude and sync the vec3
     
    Last edited: Oct 4, 2017
    Daegit likes this.
  3. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    Daegit and Zullar like this.
  4. Daegit

    Daegit

    Joined:
    Nov 20, 2015
    Posts:
    32
    Thank you guys!Now I got a idea how I could do that.
     
  5. maxnorr

    maxnorr

    Joined:
    Apr 15, 2019
    Posts:
    1
    Hey I know this is 2 years old, and they're reworking Networking in Unity; but I just figured out the solution to this after literally a whole day of grinding through examples online and documentation. It's so obvious now that I see it.

    I was trying to go Client -> ClientRpc, you have to make a stop at [Command] before you go to do the server function so that it's the server making the request.

    So go [Client] -> [Command] -> [ClientRpc]

    PLAYER HITS THEM -> TELL SERVER YOU HIT THEM -> SERVER CHANGES OPPONENTS PLAYER
     
  6. pirisok

    pirisok

    Joined:
    Apr 16, 2016
    Posts:
    3
    Can you explain it?
     
  7. Turtlehellmax

    Turtlehellmax

    Joined:
    Nov 26, 2020
    Posts:
    5
    Another 2 years have passed and I need this now. Could you please elaborate on how to tell the server you hit them? I'm using mirror, the rebooted version of the original Unity networking. Thanks in advance :)