# MapCoord —— 网络实体坐标 ↔ Metin2World 本地坐标。 # # M2Client 给的实体 pos 是「全局服务器 cm」经 position_to_godot 后的结果: # net = (sx*0.01, h, -sy*0.01) (sx/sy 含地图 BasePosition) # 而 Metin2World 的地形/物件是「地图本地」帧(tile 0 在原点,+Z 朝南): # world = ((sx-bx)*0.01, h, (sy-by)*0.01) # 两者差一个 BasePosition 平移 + Z 轴翻向。没对齐时角色会飘在几公里外的黑void里。 # # MapCoord.set_base(world.get_map_base_cm()) # Vector2,cm # var p := MapCoord.to_world(client.get_entity(vid).pos) # var sc := MapCoord.to_server_cm(player.position) # -> Vector2 (sx_cm, sy_cm) class_name MapCoord extends RefCounted static var _bx := 0.0 # BasePosition.x, cm static var _by := 0.0 static func set_base(base_cm: Vector2) -> void: _bx = base_cm.x _by = base_cm.y static func has_base() -> bool: return _bx != 0.0 or _by != 0.0 # net 帧 (sx*.01, h, -sy*.01) -> world 本地帧 ((sx-bx)*.01, h, (sy-by)*.01) static func to_world(net_pos: Vector3) -> Vector3: return Vector3(net_pos.x - _bx * 0.01, net_pos.y, -net_pos.z - _by * 0.01) # world 本地帧 -> 服务器全局 cm (sx, sy) static func to_server_cm(world_pos: Vector3) -> Vector2: return Vector2(world_pos.x * 100.0 + _bx, world_pos.z * 100.0 + _by) # 服务器 heading(度) -> world 帧 Godot yaw(弧度)。 # net 帧里南=-Z、world 帧里南=+Z,Z 翻向 -> 相对 net 帧的换算符号取反。 static func heading_to_yaw(angle_deg: float) -> float: return deg_to_rad(angle_deg + 90.0) static func yaw_to_heading(yaw_rad: float) -> float: return fposmod(rad_to_deg(yaw_rad) - 90.0, 360.0)