同步位置放大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

@@ -1,6 +1,6 @@
import { Node, Vec3, Tween, tween } from 'cc';
import { Position } from '../../Shared/protocols/base';
import { Node, Tween, tween, Vec3 } from 'cc';
import { RoleController } from '../../CC/RoleController';
import { Position } from '../../Shared/protocols/base';
/**
* RemotePlayer 远程玩家
@@ -38,8 +38,10 @@ export class RemotePlayer {
this.playerNode = playerNode;
this.playerId = playerId;
this.playerName = playerName;
this.currentPosition.set(position.x, 0, position.y);
this.targetPosition.set(position.x, 0, position.y);
const x = position.x / 1000
const y = position.y / 1000
this.currentPosition.set(x, 0, y);
this.targetPosition.set(x, 0, y);
// 获取 RoleController 组件
this.roleController = this.playerNode.getComponentInChildren(RoleController);
@@ -58,7 +60,7 @@ export class RemotePlayer {
* 收到服务器广播的移动消息时调用
*/
public updatePosition(position: Position): void {
this.targetPosition.set(position.x, 0, position.y);
this.targetPosition.set(position.x / 1000, 0, position.y / 1000);
// 计算移动方向和距离
const direction = this.targetPosition.clone().subtract(this.currentPosition);