网络a型框架中的定位问题

发布于 2025-01-14 15:11:15 字数 1594 浏览 3 评论 0原文

我不知道为什么,但有时当多个用户连接时,它们会在不同的位置生成,而我没有在代码中的任何位置指定。

<a-entity >
        <a-entity
          id="avatar"
          networked="template:#avatar-template;attachTemplateToLocal:false;"
          movement-controls="constrainToNavMesh: true"
          spawn-in-circle="radius:3"
          position="-15 0.770 25"
        >
     
          <a-entity
            class="cam"
            networked="template:#head-template;attachTemplateToLocal:false;"
            camera="active: true"
            position="0 2.5 0"
            look-controls
          >
            <a-sphere
              class="head"
              id="local-avatar"
              visible="true"
              random-color
            ></a-sphere>
          </a-entity>
        </a-entity>
</a-entity>

这是我为网络实体编写的代码。我已经给出了 position="-15 0.770 25",但相机在另一个位置生成。这破坏了所有的东西,比如速度、限制。

<script>
    NAF.schemas.getComponentsOriginal = NAF.schemas.getComponents;
    NAF.schemas.getComponents = (template) => {
      if (!NAF.schemas.hasTemplate("#head-template")) {
        NAF.schemas.add({
          template: "#head-template",
          components: [
            "position",
            "rotation",
            {
              selector: ".head",
              component: "material",
              property: "color",
            },
          ],
        });
      }
      const components = NAF.schemas.getComponentsOriginal(template);
      return components;
    };
  </script>

这用于在框架中注册实体。

I don't know why, but sometimes when multiple users connected they spawn in a different position which I didn't specify anywhere in my code.

<a-entity >
        <a-entity
          id="avatar"
          networked="template:#avatar-template;attachTemplateToLocal:false;"
          movement-controls="constrainToNavMesh: true"
          spawn-in-circle="radius:3"
          position="-15 0.770 25"
        >
     
          <a-entity
            class="cam"
            networked="template:#head-template;attachTemplateToLocal:false;"
            camera="active: true"
            position="0 2.5 0"
            look-controls
          >
            <a-sphere
              class="head"
              id="local-avatar"
              visible="true"
              random-color
            ></a-sphere>
          </a-entity>
        </a-entity>
</a-entity>

This is the code I've written for the networked entity. I've given position="-15 0.770 25", but camera is spawning in another position. Which ruins all the things like speed, constraints.

<script>
    NAF.schemas.getComponentsOriginal = NAF.schemas.getComponents;
    NAF.schemas.getComponents = (template) => {
      if (!NAF.schemas.hasTemplate("#head-template")) {
        NAF.schemas.add({
          template: "#head-template",
          components: [
            "position",
            "rotation",
            {
              selector: ".head",
              component: "material",
              property: "color",
            },
          ],
        });
      }
      const components = NAF.schemas.getComponentsOriginal(template);
      return components;
    };
  </script>

This for registering the entity in a-frame.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文