0 votes

I am trying to make a multiplayer game and my player doesn't move when I am using unreliable rpc

When I try to move the player doesn't move but the engine doesn't show any kind of errors as well.

I am using a auto-loaded script : Network, to create the players
And, a player script to control and send rpc(s) to the other side

Here is the Network script code:

extends Node

    var PORT : int = 35000
    var MAX_CLIENTS : int = 4
    var my_id : int = 1
    var IP_ADDRESS : String = ""
    var peer_ids : Array

    func _ready():
        get_tree().connect("connected_to_server", self, "connected")
        get_tree().connect("server_disconnected", self, "disconnected")
    #   get_tree().connect("connection_failed", self, "connection_falied")
        get_tree().connect("network_peer_connected", self, "peer_connected")
        get_tree().connect("network_peer_disconnected", self, "peer_disconnected")

    func create_server():
        var peer = NetworkedMultiplayerENet.new()
        var err = peer.create_server(PORT, MAX_CLIENTS)
        if err == OK:
            get_tree().network_peer = peer


    func create_client():
        var peer = NetworkedMultiplayerENet.new()
        var err = peer.create_client(IP_ADDRESS, PORT)
        if err == OK:
            get_tree().network_peer = peer



    func create_player(ID):
        var player_instance = preload("res://Player/Player2D.tscn").instance()
        player_instance.name = str(ID)
        player_instance.position = Vector2(rand_range(0, 360), rand_range(0, 240))

    func get_ids():
        my_id = get_tree().get_network_unique_id()
        peer_ids = get_tree().get_network_connected_peers()

    func connected():

    func disconnected():

    func peer_connected(id):


    func peer_disconnected(_id):

Here's the Actor script

extends Node2D

var speed : int = 300
var vel : Vector2 = Vector2.ZERO

remote var puppet_position : Vector2 = Vector2.ZERO
remote var puppet_rotation : float = 0

func movement_control():
    if Input.is_action_pressed("move_forward"):
        vel.x = speed
        vel.x = 0

remote func set_pos_and_rot(pos, rot):
    rset_unreliable("puppet_position", pos)
    rset_unreliable("puppet_rotation", rot)

And, Here's the Player code:

extends KinematicBody2D

const speed : int = 400

var velocity : Vector2

func _ready():

func _if_is_master() -> bool:
    if name == str(Network.my_id):
        return true
        modulate = Color8(255, 0, 0, 255)
        return false

func _physics_process(delta):
    if _if_is_master() == true:
        if Input.is_action_pressed("ui_up"):
            velocity.x = speed
        look_at(get_global_mouse_position()) # No need to care about this now

        var _movement = move_and_slide(velocity)

        rpc_unreliable("sync_pos", position)

puppet func sync_pos(pos):
    position = pos

And also the mainmenuscript if you need:

extends Control

func _on_Host_pressed():

func _on_Join_pressed():
Godot version 3.1
in Engine by (18 points)
edited by

Please log in or register to answer this question.

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.