Push Rigidbody Around

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Push Rigidbody Around

skeptika
2013-11-13 19:29:45

Ironically I've got rigidbody character controllers working properly across the network, but I'm struggling to get something much more basic working: allowing rigidbody character controllers to push a rigidbody object (cube) around correctly.

The object I'm trying to push, a box, obviously has a rigidbody component and collider, more importantly it also has a PhotonView and a NetworkRigidbody component (which is from the stickied topic) enabled and the PV is watching the NetworkRigidbody component. Here's the oddness I'm encountering.

If the Server/Host pushes the object, the interaction is as expected, the box is moved and it updates to both the server and the client properly, looks smooth, etc. Great.

If the Client tries to the push object, he struggles, he can't move it hardly at all (I think because it's fighting to determine the position), and to the extent he can move the object at all, it's very jerky on both the client and the server.

To dig into what was going on, I ran as both server and client within unity so I could see the state of the objects and players in question. Here's what the box looks like when you're hosting:

Here's what the box looks like when you're the client:

NetworkRigidbody is enabled on both, the Scene is the Owner, seems right so far. The difference is in Controlled locally is both enabled and is set to master on the Host. On the client, this is disabled. Is this the problem, I admit I'm at a loss to figure out how this gets set. Any help or guidance?

Comments

skeptika
2013-11-14 06:03:31

Out of frustration, I went back to an old project I did with traditional Unity networking, I even copied the exact script where this works fine in traditional Unity networking over to Photon, an exact copy line by line, and it still doesn't work.

The only thing I can tell that is different about how Photon treats this is the above screen shots, where traditional Unity networking labels the owner as a Scene, but does not seem to have the notion of "locally controlled" where Photon does.

Again, all I'm trying to do is make a rigidbody (just a regular object, not a player controller) sync position/rotation properly over the network. This works from the Server/Host perspective, but utterly fails from a Client perspective. Other than locally controlled, I'm doing this exactly as I've successfully done it with traditional Unity networking, to the extent that I even ported over the exact script used, and it still doesn't work :/

Any ideas, I'm in hang banging frustration mode :/ I'll even link webplayers of a working example with traditional Unity networking vs a webplayer of this not working with Photon if it helps illustrate the point (will also include the scripts for syncing rigidbodies over either version if that helps as well). Heeeellllp!

Tobias
2013-11-14 16:08:53

The problem will be that in PUN everything is owned by someone and only the owner of that GameObject can move / update it. So anyone who's running against a rigidbody to move it, will have a hard time moving it because it's owner keeps sending the positions it assumes being correct. I didn't know Unity can handle this case correctly. I guess they have an easier time because the host actually runs the physics and can immediately react when someone pushes the crate around. In PUN, some player "owns" the scene objects and there is more lag before that player knows someone else ran into "his" box. That will be a problem. But obviously, Unity handles the movement updates of remote players differently, so the physics can move the crate.

I am unsure if we can solve this easily, I'm sorry to say. I will check with Mike if he has some great idea...

skeptika
2013-11-14 20:06:28

Thanks for the reply, I came to this realization as I did additional testing. Unity networking does handle this, and quite well using the NetworkRigidbody script, it would be really, really awesome if you guys found a way to bring this up to parity of Unity networking. Since I'm on a deadline I'll probably have to switch back over the Unity networking, since the game uses rigidbodies a lot, but overall I prefer Photon so I'd love if it supported rigidbodies over the network!

DavoMyan
2018-02-09 14:39:52

@Tobias wrote:

The problem will be that in PUN everything is owned by someone and only the owner of that GameObject can move / update it. So anyone who's running against a rigidbody to move it, will have a hard time moving it because it's owner keeps sending the positions it assumes being correct.

I didn't know Unity can handle this case correctly. I guess they have an easier time because the host actually runs the physics and can immediately react when someone pushes the crate around.

In PUN, some player "owns" the scene objects and there is more lag before that player knows someone else ran into "his" box. That will be a problem. But obviously, Unity handles the movement updates of remote players differently, so the physics can move the crate.



I am unsure if we can solve this easily, I'm sorry to say.

I will check with Mike if he has some great idea...

I am having the same problem, did you guys find a solution? http://forum.photonengine.com/discussion/11410/please-help-sync-position-of-dynamics-scene-objects-is-driving-me-insane#latest

Lizzard4000
2018-02-10 16:03:48

You have to let the MasterClient do all the physics.
All the other clients need to disable the collisions.

That should work really well.

CarterManley
2018-12-12 17:46:02

Did anyone ever find a solution? I tried switching owner of the object with the rigidbody to the player that's the closest but when the ownership transfers there is slight lag but definitely noticeable and unattractive.

Back to top