2026-10-16
This commit is contained in:
+8
-1
@@ -29,7 +29,14 @@ func _ready() -> void:
|
||||
## recursive=true 很关键 —— 节点 authority 不自动继承,Sync 子节点必须一起设。
|
||||
func _create_player(peer_id: int) -> Node:
|
||||
var player := player_scene.instantiate()
|
||||
player.global_position = player_spawn_pos.global_position
|
||||
# ⚠ 这里只能写**局部** position,绝对不能写 global_position:
|
||||
# spawn_function 返回的节点还没入树(spawner 之后才 add_child),而 Node3D 的
|
||||
# global_transform 在未入树时是无效的 —— get_global_transform() 会 ERR_FAIL 并回退成
|
||||
# 单位矩阵,于是 set_global_transform() 把 Player 根节点的基连同**缩放一起换成单位阵**:
|
||||
# player.tscn 根节点那层 0.096096(老鼠 0.15 m 的关键)被静默抹掉,
|
||||
# 实测后果 —— 老鼠从 0.15 m 涨到 1.56 m,第一人称相机从脚底 0.1116 m 抬到 1.161 m。
|
||||
# Main 与 PlayerSpawnPos 同级、且 Main 本身无变换,所以局部坐标就等于世界坐标。
|
||||
player.position = player_spawn_pos.position
|
||||
player.name = str(peer_id)
|
||||
player.add_to_group(PLAYER_GROUP)
|
||||
player.set_multiplayer_authority(peer_id, true)
|
||||
|
||||
Reference in New Issue
Block a user