Multiplayer animation sync issues

Godot Version

V 4.2


I can’t attach files yet since I am a new member but this reddit thread features a video that is relevant to the problem.

Within my project I use doom like 8-directional sprites for characters, and is handled with this function here:

func sprite_rotation():
	var current_frame = sprite.get_frame()
	var current_progress = sprite.get_frame_progress()
	var c_fwd = -camera.global_transform.basis.z
	var fwd = -front.global_transform.basis.z
	var left = front.global_transform.basis.x
	var l_dot =
	var f_dot =
	if f_dot < -0.8: #Back sprite"B")
		sprite.set_frame_and_progress(current_frame, current_progress)
	elif f_dot > 0.8:"F") #Front sprite
		sprite.set_frame_and_progress(current_frame, current_progress)
		sprite.flip_h = l_dot > 0
		if abs(f_dot) < 0.50:"L") #Left/Right sprite
			sprite.set_frame_and_progress(current_frame, current_progress)
		elif f_dot < 0.3:"BL") #BackLeft/BackRight sprite
			sprite.set_frame_and_progress(current_frame, current_progress)
		else:"FL") #FrontLeft/FrontRight sprite
			sprite.set_frame_and_progress(current_frame, current_progress)

A basic summary of how this works is that the direction the sprite is in is determined by f_dot, the dot product of the camera front direction and the front direction of a marker3D that is a child of the sprite3D. The sprite3D is rotated instead of the marker using this line of code:

sprite_mesh.rotation.y = lerp_angle(sprite_mesh.rotation.y, atan2(velocity.x, velocity.z), 0.2)

In the video the front direction is represented by the icon.svg that orbits around the player.

The problem is that when applying this function in a multiplayer setting, from player1’s perspective, player2’s sprite updates based on player2’s own camera remotely, but instead should be updating from player1’s camera. For example,

player1’s camera is behind player2, so from player1’s perspective, IdleBack should play, whereas player2’s camera is in front of itself, so IdleFront should play.

I have tried using a MultiplayerSynchronizer to sync the players sprite.animation property, but that won’t work as that means whatever animation is playing will play regardless of other player’s perspectives. Maybe something with @rpc’s I have missed? Or maybe gaining access to another peer and using their camera as a base when called remotely?

To be honest, I have no clue on how I can get started on this and would appreciate any support on how to rectify it. If there is anything else needed or anything isn’t clear enough, please let me know.

There shouldn’t be any syncing required other then the direction the object is facing. The rendering should be done local.

As the render seems to require a camera to choose which octal it should display, only one camera should fill that role. The local player’s camera. There probably should be a global camera object to reference for the rendering view.

If you want to support spectator view, then the global camera reference should be able change to whichever camera is active (i.e. set to current).

get_viewport().get_camera_3d() returns the current active 3D camera (or null if there is none)

I had forgotten I posted this thread but you are right! I ended up finding the solution through this video here:
Thanks for the help!