Topic was automatically imported from the old Question2Answer platform.
Asked By
anllucah
The game has 3 rigidbody 2d, one is controlled by the host (player1), another by the peer (player2), and the third (ball) can be pushed by the other two, offline works well but in network player2 does not affect the ball correctly! I synchronized the bodies directly by the position! Could it be that?
extends RigidBody2D
var force = 10
const zero = Vector2(0,0)
func _process(delta):
if (!is_network_master()):
return
if (Input.is_key_pressed(KEY_UP)):
apply_impulse(zero, Vector2(0, -force))
return
if (Input.is_key_pressed(KEY_DOWN)):
apply_impulse(zero, Vector2(0, force))
return
if (Input.is_key_pressed(KEY_LEFT)):
apply_impulse(zero, Vector2(-force,0))
return
if (Input.is_key_pressed(KEY_RIGHT)):
apply_impulse(zero, Vector2(force,0))
return
var savedTrans = null
slave func updateTrans(t):
savedTrans = t
func _integrate_forces(state):
if (is_network_master()):
rpc("updateTrans",state.transform)
else:
if (savedTrans != null):
state.transform = savedTrans