Sceneform Collisions

前端 未结 1 386
生来不讨喜
生来不讨喜 2021-01-21 02:26

I\'m trying to play a sound and then destroy two objects of two different types when they collide using Sceneform. I see that Sceneform has a collision api (https://developers.g

相关标签:
1条回答
  • 2021-01-21 02:50

    The intersection methods you are trying to override do the math to calculate if two collision shapes are intersecting, I recommend against overriding them.

    Currently, there is no listener or method you can override to detect when nodes overlap. However, there are functions you can call to test for overlapping nodes.

    You can use Scene.overlapTest or Scene.overlapTestAll, which uses the CollisionShape from the Node.

    By default, it will automatically use a collision shape based on the dimensions of the Renderable attached to the Node. You can use Node.setCollisionShape to override the collision shape for the node, or to set collisions on a Node that doesn't have a Renderable.

    You can achieve the effect you are looking for by doing something like this:

    private void onUpdate(FrameTime frameTime) {
      ArrayList<Node> overlappedNodes = arSceneView.getScene().overlapTestAll(ballNode);
      for (Node node : overlappedNodes) {
        if (node instanceof PassiveNode) {
          // May want to use a flag to check that the node wasn't overlapping the previous frame.
          // Play sound if overlapping started.
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题