2020-12-27 17:15 阅读 0

Collider position

I'm trying to attach a GVRMeshCollider to a GVRSceneObject, but the collider is no where near the actual mesh. Below are some things I have tried so far. obj.attachCollider(new GVRMeshCollider(gvrContext, obj.getRenderData().getMesh())); obj.attachCollider(new GVRMeshCollider(gvrContext, true)); obj.attachCollider(new GVRMeshCollider(gvrContext, false));

The collider is only on the mesh when I position my object on position (0,0,0). As soon as I place it elsewhere, the collider doesn't move or move's only a little bit in comparison to the mesh.

This object is later in the code assigned to another object as a child object with this function: root.addChildObject(obj);

What am I doing wrong? Thanks


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

7条回答 默认 最新

  • weixin_39603604 weixin_39603604 2020-12-27 17:15

    I have porblems with MeshCollider since one of the last updates, too.

    I tried simple implementation like: http://www.gearvrf.org/bin/view/GearVRfDeveloperGuide/Picking but the onEnter event is never thrown.

    点赞 评论 复制链接分享
  • weixin_39603588 weixin_39603588 2020-12-27 17:15


    点赞 评论 复制链接分享
  • weixin_39637661 weixin_39637661 2020-12-27 17:15

    Pull request #812 should fix these issues. Please give it a try and let me know if it does. This fix hasn't been merged yet. Here is how to get it: git pull https://github.com/NolaDonato/GearVRf.git pickvisible2

    点赞 评论 复制链接分享
  • weixin_39603604 weixin_39603604 2020-12-27 17:15

    I pulled the request #812 and tested it with an example scene and it's still not working.

    It seems that two objects are picked when executed onInit() - but the onExit event is never thrown, same for onEnter or any other event when onInit is finished.

    I am adding the PickHandler and the GVRPicker like that:

        this.pickHandler = new PickHandler();
                new GVRPicker(gvrContext, this.mainScene));

    and I am adding the colliders like:

        parent.attachComponent(new GVRMeshCollider(this.getGVRContext(), false));
        child1.attachComponent(new GVRMeshCollider(this.getGVRContext(), false));
        child2.attachComponent(new GVRMeshCollider(this.getGVRContext(), false));

    The PickHanlder looks like:

        public void onEnter(GVRSceneObject sceneObj, GVRPicker.GVRPickedObject collision) {
                Log.d(TAG, "onEnter event...");

    Same for the onExit event - the logs shows two onEnter event information, during startup, but no more log information about the events or stop at breakpoints in debug mode.

    点赞 评论 复制链接分享
  • weixin_39637661 weixin_39637661 2020-12-27 17:15

    this.mainScene.getMainCameraRig().getOwnerObject().attachComponent( new GVRPicker(gvrContext, this.mainScene));

    I think you are attaching it to the wrong object. I know the demos do this but that is because early on the picker would always pick from the camera no matter what it was attached to. This was wrong so I tried to change it to use the scene object. This broke the demos because they don't use the right object. So I changed it in #812 to default to picking from the camera if you don't attach it to anything and picking from the scene object if you do. So, to attach it to the camera you have to do: this.mainScene.getMainCameraRig().getHeadTransformObject().attachComponent( new GVRPicker(gvrContext, this.mainScene)); If you just make a GVRPicker and don't attach it to anything, it will do the same thing - pick from the camera. So you can do: GVRPicker myPicker = new GVRPicker(gvrContext, this.mainScene); and it will pick from the camera (which is what you want). I am the one who broke picking so you can blame me for your troubles :-) My fix wasn't thoroughly tested and then I went on vacation and they merged it :-(

    点赞 评论 复制链接分享
  • weixin_39894104 weixin_39894104 2020-12-27 17:15

    Pull request #812 fixed this for me, thanks!

    点赞 评论 复制链接分享
  • weixin_39603604 weixin_39603604 2020-12-27 17:15

    Works for me, too!

    Thank you for the fix...

    点赞 评论 复制链接分享