Search Unity

Third Party [PUN2] Grabbing a ball with Transform & Rigidbody Views

Discussion in 'Multiplayer' started by PascalTheDog, Jan 27, 2022.

  1. PascalTheDog

    PascalTheDog

    Joined:
    Mar 16, 2015
    Posts:
    86
    Hey,

    I have a simple scene with just a basketball, which has both Transform View and Rigidbody View components on it. Players can grab that ball. What the grabbing logic does is disable the physics on the ball (by making it kinematic) and parent the ball to the player who grabbed it; now its position is determined by that parent's, not by physics. Physics are re-enabled the moment the player throws the ball.

    The Rigidbody View works fine until a player grabs the ball. Everything is going fine on the grabber's side, but the ball acts very weird on the other player's; it's teleporting around in a jittery fashion, until the ball is thrown at which point it teleports to where the ball actually is and resumes proper operation.

    Any idea of where the problem might be coming from? Assistance would be greatly appreciated.

    Cheers.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    My guess: You don't sync that the ball is grabbed. Maybe you don't reparent the ball as well. Or you still get position updates but while it's grabbed, they don't mean the same thing (if you reparented it).
     
  3. PascalTheDog

    PascalTheDog

    Joined:
    Mar 16, 2015
    Posts:
    86
    Making the Grab and Throw methods RPCs solved the problem. Seems like I'm starting to get the hang of it; thanks!
     
    tobiass likes this.
  4. j0schm03

    j0schm03

    Joined:
    Jun 21, 2018
    Posts:
    16
    I'm dealing with this same challenge right now. Our approach thus far has been, when the user grabs the object ownership is transferred to that user. But we are still getting weird results on the other players observing the object going all crazy in random directions and then flying back to the correct position after they stop grabbing.

    But I think you've got me looking in the right direction now. Would you be able to provide a small code snippet of how your handling the grabbing in the RPC? That would be awesome if possible!

    Thanks!