接入ResLogin.otherPlayers
This commit is contained in:
@@ -43,7 +43,7 @@ export class PlayerController extends Component {
|
||||
this.playerInfo = playerInfo;
|
||||
const x = playerInfo.position.x / 1000
|
||||
const y = playerInfo.position.y / 1000
|
||||
this.lastSentPosition.set(x, 0, y);
|
||||
this.lastSentPosition.set(x, y, 0);
|
||||
|
||||
// 获取 RoleController 组件
|
||||
this.roleController = this.node.getComponentInChildren(RoleController);
|
||||
@@ -109,11 +109,11 @@ export class PlayerController extends Component {
|
||||
|
||||
// W - 向前
|
||||
if (this.keyStates.get(KeyCode.KEY_W)) {
|
||||
this.moveDirection.z -= 1;
|
||||
this.moveDirection.y += 1;
|
||||
}
|
||||
// S - 向后
|
||||
if (this.keyStates.get(KeyCode.KEY_S)) {
|
||||
this.moveDirection.z += 1;
|
||||
this.moveDirection.y -= 1;
|
||||
}
|
||||
// A - 向左
|
||||
if (this.keyStates.get(KeyCode.KEY_A)) {
|
||||
@@ -144,7 +144,7 @@ export class PlayerController extends Component {
|
||||
|
||||
// 更新朝向(让角色面向移动方向)
|
||||
if (this.moveDirection.lengthSqr() > 0) {
|
||||
const targetAngle = Math.atan2(this.moveDirection.x, -this.moveDirection.z) * (180 / Math.PI);
|
||||
const targetAngle = Math.atan2(this.moveDirection.x, -this.moveDirection.y) * (180 / Math.PI);
|
||||
this.node.setRotationFromEuler(0, targetAngle, 0);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ export class PlayerController extends Component {
|
||||
|
||||
// 如果移动距离超过阈值,发送移动请求
|
||||
if (distance >= this.moveSendThreshold) {
|
||||
this.sendMoveRequest(currentPos.x, currentPos.z);
|
||||
this.sendMoveRequest(currentPos.x, currentPos.y);
|
||||
this.lastSentPosition.set(currentPos);
|
||||
}
|
||||
}
|
||||
@@ -176,12 +176,12 @@ export class PlayerController extends Component {
|
||||
/**
|
||||
* 发送移动请求到服务器
|
||||
*/
|
||||
private async sendMoveRequest(x: number, z: number): Promise<void> {
|
||||
private async sendMoveRequest(x: number, y: number): Promise<void> {
|
||||
try {
|
||||
const netManager = NetManager.getInstance();
|
||||
const result = await netManager.callMsg(new MoveMessagePair(), {
|
||||
x: Math.round(x * 1000),
|
||||
y: Math.round(z * 1000)
|
||||
y: Math.round(y * 1000)
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
@@ -194,8 +194,8 @@ export class PlayerController extends Component {
|
||||
const serverPos = result.position;
|
||||
const x = serverPos.x / 1000
|
||||
const y = serverPos.y / 1000
|
||||
this.node.setPosition(x, 0, y);
|
||||
this.lastSentPosition.set(x, 0, y);
|
||||
this.node.setPosition(x, y, 0);
|
||||
this.lastSentPosition.set(x, y, 0);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[PlayerController] 发送移动请求异常:', error);
|
||||
|
||||
Reference in New Issue
Block a user