Topic was automatically imported from the old Question2Answer platform.
Asked By
Tova
i am creating a multiplayer game, i have a player who is a KinematicBody2D and i use move_and_slide 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)
else:
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
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.
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
Tova | 2018-07-04 15:08
If you have another question you should open a new thread