本帖最后由 啊啵呲嘚 于 2023-7-12 11:28 编辑
自己加了一个手同步位置的脚本
@Core.Class
export default class SyncPlayerLoc extends Core.Script {
public static Instance: SyncPlayerLoc;
protected override onStart(): void {
SyncPlayerLoc.Instance = this;
}
/**
* 设置玩家位置
* @param player 玩家
* @param loc 位置
* @returns
*/
@Core.Function(Core.Client)
private setPlayerLoc(player: Gameplay.Player, loc: Type.Vector) {
console.log("setPlayerLoc", loc.add(Type.Vector.up.multiply(10)));
if (!player) return;
player.character.worldLocation = loc.add(Type.Vector.up.multiply(10));
}
/**
* 同步玩家位置
* @param player 发起同步的玩家
* @param playerIds 需要同步的玩家id
*/
@Core.Function(Core.Server)
syncPlayerLoc(player: Gameplay.Player, playerIds: number[] = []) {
console.log("getPlayerLoc", playerIds);
let wLoc: Gameplay.Player[];
if (!playerIds || playerIds.length == 0) {
wLoc = Gameplay.getAllPlayers();
} else {
wLoc = Gameplay.getAllPlayers().filter((e) => {
const cha = e.character;
return !cha.isMoving || !cha.isJumping || playerIds.indexOf(e.getPlayerID()) != -1;
});
}
wLoc.forEach((e) => {
if (e.getPlayerID() == player.getPlayerID()) return;
this.setPlayerLoc(e, e.character.worldLocation);
});
}
}
|