【问题标题】:AFrame: Problem with physics; dynamic-body & grabbableAFrame:物理问题;动态车身和可抓取
【发布时间】:2020-11-18 22:22:48
【问题描述】:

问题:

我想制作一个用户可以扔的球。使用我目前的实现,物理工作,但我无法举起球。但是,如果我删除“动态体”,我可以完全按照我的预期抓住球,然后移动它。哎呀,我尝试将其更改为“静态体”,它仍然有效。每当我混合可抓取和动态主体时,问题似乎就出现了。我知道在旧版本中应该可以,因为我正在使用本教程:https://www.youtube.com/watch?v=SKYfYd3pk4I

但是,他正在使用最新的超级手包中没有的渐进式控件,我不知道这是否会改变任何东西。我在这里做错了什么吗?


以下是我可能会影响结果的代码片段:

我的 A-Frame 包:

<head>
  <!-- A-Frame -->
  <script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
  
  <!-- A-Frame Components -->
  <!-- A-Frame Particle System -->
  <script src="https://unpkg.com/aframe-particle-system-component@1.0.9/dist/aframe-particle-system-component.min.js"></script>
  <script src="https://unpkg.com/aframe-environment-component/dist/aframe-environment-component.min.js"></script>
 
  <!-- A-Frame Event System -->  
  <script src="https://unpkg.com/aframe-event-set-component@4.2.1/dist/aframe-event-set-component.min.js"></script> 

  <!-- A-Frame Extras Add-Ons -->  
  <script src="https://cdn.jsdelivr.net/gh/donmccurdy/aframe-extras@v6.1.1/dist/aframe-extras.min.js"></script>
  
  <!-- A-Frame Physics -->  
  <script src="https://cdn.jsdelivr.net/gh/n5ro/aframe-physics-system@v4.0.1/dist/aframe-physics-system.min.js"></script>
 
  <!-- A-Frame Physics Extra Add-On -->  
  <script src="https://unpkg.com/aframe-physics-extras@0.1.2/dist/aframe-physics-extras.min.js"></script>

  <!-- A-Frame Super Hands -->  
  <script src="https://unpkg.com/super-hands@3.0.0/dist/super-hands.min.js"></script> 
  
</head>

我的问题领域:

<!-- Ball -->                            
              <a-entity 
                id="Ball-2" 
                position="0 0 0">
                <a-sphere 
                  id="Ball-2-collider"
                  grabbable
                  dynamic-body="mass: 0.2; linearDamping: 0.05; angularDamping: 0.3; shape: sphere; 
sphereRadius: 0.125;"
                  class="interactable ball"
                  radius="5"
                  position="0 0.6 3.8"
                  scale="0.02 0.02 0.02">
                  <a-entity
                    id="ball-2-mesh" 
                    position="0 -6 0"
                    rotation="0 0 0"
                    scale="600 600 600"
                    gltf-model="#Ball-glb"
                    color="#FFFFFF">
                  </a-entity>  
                </a-sphere>
              </a-entity> 

我的控制器设置:

          <a-entity id="camera-rig" position="0 -1.20 4" rotation="0 150 0">
            <a-camera 
              user-height="1.6"
              active="true">     
              <a-entity 
                cursor="fuse: true; fuseTimeout: 1000" 
                raycaster="objects: .interactable"
                animation__fusing="property: scale; startEvents: fusing; easing: linear; dur: 1000; from: 1 1 1; to: 3 3 3"
                animation__leave="property: scale; startEvents: mouseleave; easing: linear; dur: 1; from: 1 1 1; to: 1 1 1"
                animation__click="property: scale; startEvents: click; easing: linear; dur: 150; from: 3 3 3; to: 1 1 1"
                position="0 0 -1"
                geometry="primitive: sphere; radius: 0.005"
                material="color: #FF00FF; shader: flat; opacity: 0.5">                
              </a-entity>         
            </a-camera>
            
            <a-entity sphere-collider="objects: .interactable" handModelStyle: lowPoly; super-hands hand-controls="hand: left"></a-entity>
            <a-entity sphere-collider="objects: .interactable" handModelStyle: lowPoly; super-hands hand-controls="hand: right"></a-entity>  
          </a-entity>    

最后,定义重力的场景:

<a-scene embedded antialias="false" physics="gravity: -9.8; debug: true">

【问题讨论】:

    标签: aframe webvr


    【解决方案1】:

    感谢:https://github.com/bryik/aframe-ball-throw/blob/master/index.html

    我找到了罪魁祸首。 我需要将静态主体添加到我的手实体中,以便可以检测到碰撞。不知道为什么之前在没有它们的情况下检测到碰撞。

    修改代码:

            <a-entity static-body="shape: sphere; sphereRadius: 0.02;" sphere-collider="objects: .interactable" handModelStyle: lowPoly; super-hands hand-controls="hand: left"></a-entity>
            <a-entity static-body="shape: sphere; sphereRadius: 0.02;" sphere-collider="objects: .interactable" handModelStyle: lowPoly; super-hands hand-controls="hand: right"></a-entity>  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-10
      • 2022-01-17
      • 1970-01-01
      • 2018-08-10
      • 2019-12-26
      • 2011-08-01
      相关资源
      最近更新 更多