同步位置放大1000倍取整

This commit is contained in:
janing
2025-12-18 13:43:28 +08:00
parent 637978357f
commit 4b3b94a450
3 changed files with 18 additions and 9 deletions

View File

@@ -41,7 +41,9 @@ export class PlayerController extends Component {
*/
public init(playerInfo: PlayerInfo): void {
this.playerInfo = playerInfo;
this.lastSentPosition.set(playerInfo.position.x, 0, playerInfo.position.y);
const x = playerInfo.position.x / 1000
const y = playerInfo.position.y / 1000
this.lastSentPosition.set(x, 0, y);
// 获取 RoleController 组件
this.roleController = this.node.getComponentInChildren(RoleController);
@@ -190,8 +192,10 @@ export class PlayerController extends Component {
// 服务器可能会修正位置,使用服务器返回的位置
if (result.position) {
const serverPos = result.position;
this.node.setPosition(serverPos.x, 0, serverPos.y);
this.lastSentPosition.set(serverPos.x, 0, serverPos.y);
const x = serverPos.x / 1000
const y = serverPos.y / 1000
this.node.setPosition(x, 0, y);
this.lastSentPosition.set(x, 0, y);
}
} catch (error) {
console.error('[PlayerController] 发送移动请求异常:', error);