AFrame:物理问题;动态主体和可抓取

问题描述 投票:0回答:2

问题:

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

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


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

我的A型框架包:

<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/[email protected]/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/[email protected]/dist/aframe-event-set-component.min.js"></script> 

  <!-- A-Frame Extras Add-Ons -->  
  <script src="https://cdn.jsdelivr.net/gh/donmccurdy/[email protected]/dist/aframe-extras.min.js"></script>
  
  <!-- A-Frame Physics -->  
  <script src="https://cdn.jsdelivr.net/gh/n5ro/[email protected]/dist/aframe-physics-system.min.js"></script>
 
  <!-- A-Frame Physics Extra Add-On -->  
  <script src="https://unpkg.com/[email protected]/dist/aframe-physics-extras.min.js"></script>

  <!-- A-Frame Super Hands -->  
  <script src="https://unpkg.com/[email protected]/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
2个回答
2
投票

感谢这个: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>  

0
投票

谢谢!你的帖子对我帮助很大!

© www.soinside.com 2019 - 2024. All rights reserved.