+1 vote

Basically I'm trying to convert my game to work with multiplayer. Players control a spaceship and can fire lasers, and I have some code that detects which player shot the laser to do some damage calculations and other stuff. When the client player shoots, on the host players side the client player is detected as an EncodedObjectAsID, not as a KinematicBody, which is basically game breaking.

I'm still pretty new to the engine and understand very little about networking, so I'm not sure what i can do about this.

in game client shooting responses:
client side: laser shot by: [KinematicBody2D:1959]
host side: laser shot by: [EncodedObjectAsID:2913]

laser firing code:
func fire(body):
    if online && is_network_master() && can_shoot && Input.is_action_just_pressed(shoot):
        rpc("fire_code", body)
    elif !online && can_shoot && Input.is_action_just_pressed(shoot):

remotesync func fire_code(body):
    var laser = LASER.instance()
    laser.connect("laser_hit", other_player, "take_damage")
    laser.shot_by = body
    print("laser shot by: ", laser.shot_by)
    laser.position = $bullet_spawn.global_position
    can_shoot = false
    Global.create_timer(laser_cooldown, body, "reactivate_laser", true)
in Engine by (100 points)

1 Answer

+2 votes
Best answer

Did some more searching and apparently Objects can't be passed through RPC calls by default due to security reasons.

by (100 points)
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.