The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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?

in Engine by (71 points)

1 Answer

+2 votes
Best answer

It works fine for me.

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
by (324 points)
edited by

Thank you it was very helpful

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.