-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsync_mesh.gd
More file actions
41 lines (25 loc) · 902 Bytes
/
sync_mesh.gd
File metadata and controls
41 lines (25 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extends MeshInstance3D
# Move the box in sync with all peers
var seek: float:
set = set_seek,
get = get_seek
@onready var _player: AnimationPlayer = $AnimationPlayer
func _ready():
NetworkSync.register_process(self, "_sync_process")
NetworkSync.register_variable(self, "seek", "_on_seek_changed", NetworkSync.SYNC_RESET)
# Manual process so we can process the animations in sync.
_player.playback_process_mode = AnimationPlayer.ANIMATION_PROCESS_MANUAL
func get_seek() -> float:
return _player.get_current_animation_position()
func set_seek(s):
_player.seek(s)
func _sync_process(delta: float):
_player.advance(delta)
func _on_seek_changed():
## This function is called only when a reset occurs thanks to: NetworkSync.SYNC_RESET
## In alternative you can use this function instead
## ```
## if NetworkSync.is_resetted():
## _player.seek(seek)
## ```
_player.seek(seek)