Godot Version
V 4.2
Question
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. https://www.reddit.com/r/godot/comments/1dv2d5d/multiplayer_animation_sync_issues/
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 = left.dot(c_fwd)
var f_dot = fwd.dot(c_fwd)
if f_dot < -0.8: #Back sprite
sprite.play(current_state+&"B")
sprite.set_frame_and_progress(current_frame, current_progress)
elif f_dot > 0.8:
sprite.play(current_state+&"F") #Front sprite
sprite.set_frame_and_progress(current_frame, current_progress)
else:
sprite.flip_h = l_dot > 0
if abs(f_dot) < 0.50:
sprite.play(current_state+&"L") #Left/Right sprite
sprite.set_frame_and_progress(current_frame, current_progress)
elif f_dot < 0.3:
sprite.play(current_state+&"BL") #BackLeft/BackRight sprite
sprite.set_frame_and_progress(current_frame, current_progress)
else:
sprite.play(current_state+&"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.