+2 votes

I have a simple rigid body cube and I want to sync its position and rotation between clients and server in the network. What is the correct way?

I've attached this script to all my boxes (rigid bodies):

extends RigidBody
func _physics_process(delta):
   rpc_unreliable("update_pos_rot", translation, rotation)
   pass
puppet func update_pos_rot(pos, rot):
   translation = pos
   rotation = rot

It kind of works but I have this error in the console:

ERROR: _process_rpc: Condition ` !_can_call_mode(p_node, rpc_mode, p_from) ` is true.
At: core/io/multiplayer_api.cpp:286
asked Mar 25 in Engine by wowzzers (28 points)

1 Answer

+2 votes

I don't know if there is a correct way, but considering that you shouldn't directly set position and rotation of rigidbodies (See here), I'd only simulate physics on the server and on clients use no rigidbodies at all and instead only sync the position of meshinstances, or kinematicbodies on client with rigidbodies on the server.

answered Mar 27 by omggomb (210 points)

Thank you for the answer! I'll try to sync mesh instances instead.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.