0 votes

i am creating a multiplayer game, i have a player who is a KinematicBody2D and i use moveandslide to make it move. in my physics_process i have:

func _physics_process(delta):
if is_network_master():
    velocity = Vector2(0,0)
    velocity += analog_velocity

    if velocity.length() > 0:
        velocity = velocity.normalized() * speed
    rset_unreliable("slave_velocity", velocity)

    velocity = slave_motion
velocity = move_and_slide(velocity)

if not is_network_master():
    slave_velocity = velocity

so when i run two players the both move fine, but if one of the players collides with an object it will mess up position on other players screen (cause it will slide of a corner of the collision object and continue to move)
how would i fix that? i was thinking about using position but then collisions would not work

in Engine by (175 points)

1 Answer

0 votes
Best answer

You will have to use position at some point.
Network movement is unreliable, packets get lost and you accumulate error over time. So you must sync the position regularly to make sure things don't go nuts.
I would suggest you look into a technique called "Dead Reckoning":



Sorry it's probably not beginner-level but you will run into that soon or later if you do multiplayer.

by (28,788 points)
selected by

thanks, it helped a lot :) I managed to fix it temporarily, it's still a bit glitchy but it works fine for now

I see that you are experienced, could you also help me with cameras? i have multiple players on the same map, and each of them needs to have its own camera, but apparently you can only have one camera active per scene. I got an answer that i should use Viewport but I'm not familiar with that and documentation didn't really help either :/

If you have another question you should open a new thread ;)

i already did, thats where i got the information that i should use viewports, but a more detailed answer would be appreaciated :)

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.
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 webmaster@godotengine.org with your username.